Codeforces Round #577 (Div. 2) 题解
比赛链接:https://codeforc.es/contest/1201
A. Important Exam
题意:有\(n\)个人,每个人给出\(m\)个答案,每个答案都有一个分值\(a_i\),每个问题的正确答案不确定,询问最大可能的得分为多少。
分析:对于每个问题贪心最大数量就好。
AC代码:
#include <bits/stdc++.h>
#define SIZE 500007
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef long long ll;
void io() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}
int n, m, t;
string s;
map<char, int>mp[1005];
int main() {
	io(); cin >> n >> m;
	rep(i, 1, n) {
		cin >> s;
		rep(j, 0, s.length() - 1) {
			mp[j + 1][s[j] - 'a']++;
		}
	}
	ll ans = 0;
	rep(i, 1, m) {
		cin >> t;
		int maxx = 0;
		for (auto it : mp[i]) {
			maxx = max(maxx, it.second);
		}
		ans += 1ll * maxx * t;
	}
	cout << ans;
}
 
B. Zero Array
题意:给出一个\(n\)个数的数列,每次操作能将其中任意两个数\(-1\),询问能否将这个数列全部减为零。
分析:首先由于每次减少的总数为2,因此和为奇数的数列不行。再考虑和为偶数的数列,发现当且仅当最大的数值大于数列总和的一半时不存在。
AC代码:
#include <bits/stdc++.h>
#define SIZE 500007
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef long long ll;
void io() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}
int n, m, t;
ll a[SIZE];
int main() {
	io(); cin >> n;
	ll sum = 0;
	rep(i, 1, n) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a + 1, a + 1 + n);
	if (sum & 1) { cout << "NO"; return 0; }
	else {
		if (a[n] > sum / 2)cout << "NO";
		else cout << "YES";
	}
}
 
C. Maximum Median
题意:给定一个\(n\)个数的数列和\(k\)次操作,每次能将数列中的一个数\(+1\)。询问\(k\)次操作后数列中位数的最大值为多少。(\(n\)为奇数)
分析:先排序,然后为了使中位数最大,我们显然只用对当前数列中位数及中位数之后的数进行操作。于是我们考虑贪心地加,下面举个例子:
7 7
1 2 3 4 5 6 10
第一步:1 2 3 5 5 6 10
第二步:1 2 3 6 6 6 10
第三步:1 2 3 7 7 8 10
这种贪心的构造通过一种类似于前缀和的想法即可实现,AC代码:
#include <bits/stdc++.h>
#define SIZE 500007
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef long long ll;
void io() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}
int n, m, t, k;
ll a[SIZE], pre[SIZE];
int main() {
	io(); cin >> n >> k;
	rep(i, 1, n) cin >> a[i];
	sort(a + 1, a + 1 + n);
	rep(i, (n + 3) / 2, n) {
		pre[i] = pre[i - 1] + (i - (n + 1) / 2) * (a[i] - a[i - 1]);
		if (pre[i] > k) {
			ll tmp = ((k - pre[i - 1]) / (i - (n + 1) / 2));
			cout << a[i - 1] + tmp;
			return 0;
		}
	}
	ll tmp = (k - pre[n]) / ((n + 1) / 2);
	cout << tmp + a[n];
}
 
D题下午打完多校再写吧。。。
upd:咕咕咕
Codeforces Round #577 (Div. 2) 题解的更多相关文章
- Codeforces Round #182 (Div. 1)题解【ABCD】
		
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
 - Codeforces Round #608 (Div. 2) 题解
		
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
 - Codeforces Round #525 (Div. 2)题解
		
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
 - Codeforces Round #528 (Div. 2)题解
		
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
 - Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
		
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
 - Codeforces Round #577 (Div. 2)  D. Treasure Hunting
		
Codeforces Round #577 (Div. 2) D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...
 - Codeforces Round #677 (Div. 3) 题解
		
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
 - Codeforces Round #665 (Div. 2) 题解
		
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
 - Codeforces Round #160 (Div. 1) 题解【ABCD】
		
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
 
随机推荐
- JavaSwing开发简单的银行管理系统 附源码
			
开发环境: Windows操作系统开发工具: MyEclipse/Eclipse+Jdk+mysql数据库 运行效果图:
 - vue自定义日期选择,类似美团日期选择,日历控件,vue日历区间选择
			
一个日历的控件,基于vue的,可以日历区间选择,可用于酒店日历区间筛选,动手能力强,可以修改成小程序版本的,先上效果图 里面的颜色样式都是可以修改的 选择范围效果 话不多说,直接上干货,代码可以直接复 ...
 - 栈的简单应用之中缀表达式转后缀表达式(C语言实现逆波兰式)
			
一.前言 普通人在书写计算式时会选择中缀表达式,这样符合人脑的认知习惯.可计算机处理时后缀表达式才能使处理速度更快,其原因是利用堆栈结构减少计算机内存访问.同时它也是一个很好锻炼栈这个数据结构的应 ...
 - python的selenium实现自动登陆
			
知道思想,参考其他文档,python的request模块和selenium模块都可以实现get_cookie()和 add_cookie()的功能. 由于现在在学习selenium自动化测试,我选用s ...
 - 无缘诺贝尔奖的George Dantzig——线性规划之父
			
无缘诺贝尔奖的George Dantzig——线性规划之父 王军强,2012年11月2日 “线性规划之父”的George Dantzig,与“计算机之父”.“博弈论之父”John Von Neuman ...
 - xrdp---远程桌面连接
			
xrdp is an Open Source Remote desktop Protocol server, which allows you to RDP to your Linux server ...
 - 后台执行linux命令
			
/** * * 方法说明:移植执行linux命令 * * @param cmdStr 需要执行的linux命令 * @return 执行命令后的输出(如果是启动一个进程,则可能一直无法返回) * @t ...
 - json_encode中文不转义问题
			
//php5.3之后才有这个参数,这样存入数据库中的中文json数据就不会转义,也能被正确解析1JSON_UNESCAPED_UNICODE(中文不转为unicode ,对应的数字 256) JSON ...
 - C++ vector的用法(转)
			
原文链接:https://blog.csdn.net/qinyuehong/article/details/92837359
 - c++primer练习题
			
2.7 输出地址和姓名(1 #include <iostream> using namespace std; int main() { int 距离; cout << &quo ...