当前位置: 首页 > article >正文

2024ICPC网络赛第一场

vp链接:https://qoj.ac/contest/1794

A. World Cup

最终答案与中国队能力值的排名有关,具体每个情况手推一下,用 if else 即可通过。

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int t, a[40];
    cin >> t;
    while (t--) {
        int num = 0;
        for (int i = 0; i < 32; i++) {
            cin >> a[i];
            if (a[i] <= a[0]) num++;
        }
        if (num == 32) puts("1");
        else if (num >= 28) puts("2");
        else if (num >= 14) puts("4");
        else if (num >= 7) puts("8");
        else if (num >= 3) puts("16");
        else puts("32");
    }
    return 0;
}

F. Make Max

每一个数都能更新左右比它小的数,直到遇到一个大于等于它的数为止。从小到大一个个更新,更新次数一定最多,但在计算结果的时候只需要计算数量,不用考虑计算顺序。

利用单调栈求出每一个 a_i 左边第一个大于等于它的数的位置 lef_i 和右边第一个大于等于它的数的位置 rig_i

计算结果的时候要注意,如果 a_i = a_{lef_i},即 a_i 与左边第一个大于等于它的数相等的时候,只需要记右边小于它的数的个数,不然会跟前面的算重;其余情况都要加上左右小于它的数的个数。

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;
int n, a[N], lef[N], rig[N];
stack<int> s;

inline int read() {
    int x = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

int main () {
    int t = read();
    while (t--) {
        n = read();
        for (int i = 1; i <= n; i++) a[i] = read();
        for (int i = 1; i <= n; i++) {
            if (s.empty() || a[i] < a[s.top()]) s.push(i);
            else {
                while (!s.empty() && a[i] >= a[s.top()]) {
                    rig[s.top()] = i;
                    s.pop();
                }
                s.push(i);
            }
        }
        while (!s.empty()) rig[s.top()] = n + 1, s.pop();
        for (int i = n; i; i--) {
            if (s.empty() || a[i] < a[s.top()]) s.push(i);
            else {
                while (!s.empty() && a[i] >= a[s.top()]) {
                    lef[s.top()] = i;
                    s.pop();
                }
                s.push(i);
            }
        }
        while (!s.empty()) lef[s.top()] = 0, s.pop();
        long long ans = 0LL;
        for (int i = 1; i <= n; i++) {
            if (!lef[i] || a[lef[i]] != a[i]) ans += rig[i] - lef[i] - 2;
            else ans += rig[i] - i - 1;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

G. The Median of the Median of the Median

#include <bits/stdc++.h>
using namespace std;

const int N = 2010;
int n, suma[N], a[N], b[N][N], c[N][N];

inline int read() {
	int x = 0, f = 1; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}

bool check(int x) {
	for (int i = 1; i <= n; i++) suma[i] = suma[i - 1] + (a[i] >= x);
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			c[i][j] = b[i][j] = (2 * (suma[j] - suma[i - 1]) > (j - i + 1));
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++) c[i][j] += c[i][j - 1];
	for (int j = 1; j <= n; j++)
		for (int i = j - 1; i >= 1; i--) c[i][j] += c[i + 1][j];
	int sumc = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			sumc += (2 * c[i][j]) > (j - i + 1) * (j - i + 2) / 2;
	return 2 * sumc > n * (n + 1) / 2;
}

int main() {
	n = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	int l = 0, r = 1e9 + 1;
	while (l <= r) {
		int mid = l + r >> 1;
		if (check(mid)) l = mid;
		else r = mid;
	}
	printf("%d\n", l);
	return 0;
}

M. Find The Easiest Problem

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int t, n;
    string team, status;
    char prob;
    cin >> t;
    while (t--) {
        cin >> n;
        set<string> st[30];
        for (int i = 1; i <= n; i++) {
            cin >> team >> prob >> status;
            if (status == "accepted") st[prob - 'A'].insert(team);
        }
        int idx = 0;
        for (int i = 1; i <= 'Z' - 'A'; i++) {
            if (st[idx].size() < st[i].size()) idx = i;
        }
        printf("%c\n", 'A' + idx);
    }
    return 0;
}


http://www.kler.cn/news/309535.html

相关文章:

  • 【源代码+仿真+原理图+技术文档+演示视频+软件】基于物联网技术的宠物居家状况监测系统设计与实现
  • Kotlin 极简小抄 P1(变量与常量、基本数据类型、流程控制)
  • 【C++】一次rustdesk-server编译记录
  • 从数据仓库到数据中台再到数据飞轮:社交媒体的数据技术进化史
  • 计算机人工智能前沿进展-大语言模型方向-2024-09-12
  • LED灯、蜂鸣器、继电器的控制
  • 【店雷达全网图搜比价盘点】1688、淘宝、阿里国际、亚马逊、速卖通5大平台
  • 一次渲染十万条数据:前端技术优化(上)
  • Java 入门指南:JVM(Java虚拟机)垃圾回收机制 —— 新一代垃圾回收器 ZGC 收集器
  • 分布式中间件-redis相关概念介绍
  • B3636 文字工作
  • LabVIEW编程快速提升的关键技术
  • 【VScode】配置多账户连接远程服务器
  • PWN College 关于sql盲注
  • 【Hot100】LeetCode—72. 编辑距离
  • vue2制作高复用页面
  • 系统架构师考试学习笔记第五篇——架构设计补充知识(25)专业英语
  • Spring部分常见面试题
  • 关于Spring Cloud Gateway中 Filters的理解
  • 健身房预约小程序定制搭建,数字化运营管理
  • Python+Pytest框架,“api_key.py文件怎么编写“?
  • 【乐企-业务篇】生成发票左上角二维码
  • Linux和C语言(Day 12)
  • 华南医电科技集团受邀出席中马建交50周年高级别经贸合作交流活动
  • [Redis] Redis中的set和zset类型
  • 云轴科技ZStack 获鲲鹏应用创新大赛2024上海赛区决赛一等奖
  • vue3-print打印eletable某一行的数据
  • TI AM62X Secure Boot 流程简述
  • (黑马点评)六、好友关注系列功能实现
  • C语言 | Leetcode C语言接雨水II