Codeforces Round #538 (Div. 2) A,B,C,D,E

视频题解戳我

题目戳我

 

A. Got Any Grapes?

解题思路:看清题意,手动模拟一下,看看每个人的需求能不能满足。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
using namespace std;
typedef long long ll;
int main() {
	std::ios::sync_with_stdio(0);
	int x, y, z, a, b, c;
	cin >> x >> y >> z;
	cin >> a >> b >> c;
	bool flag1 = true;
	if (a < x) {
		flag1 = false;
	} else {
		a -= x;
		if (a+b < y) {
			flag1 = false;
		} else {
			if (a+b+c < y+z) {
				flag1 = false;
			}
		}
	}
	if (flag1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

 

B. Yet Another Array Partitioning Task

解题思路:总共要取m*k个数,那当然是取从大到小的前m*k个数,将他们标记上,最后扫一遍,出现了m个就是一个断电。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
const int maxn=2e5+5;
ll n,m,k;
struct node{
	ll id;
	ll val;
	int fg;
}a[maxn];
bool cmp1(node a,node b){
	return a.val>b.val;
}
bool cmp2(node a,node b){
	return a.id<b.id;
}
int main(){
	std::ios::sync_with_stdio(0);
	cin>>n>>m>>k;
	for(int i=1;i<=n;++i){
		cin>>a[i].val;
		a[i].id=i;
		a[i].fg=0;
	}
	sort(a+1,a+1+n,cmp1);
	for(int i=1;i<=m*k;++i){
		a[i].fg=1;
	}
	sort(a+1,a+1+n,cmp2);
	ll cnt=0,sum=0,num=0;
	vector<int> ans;
	for(int i=1;i<=n;++i){
		if(a[i].fg==1){
			sum+=a[i].val;
			num++;
		}
		if(num==m){
			num=0;
			ans.push_back(i);
			cnt++;
		}
		if(cnt==k)	break;
	}
	cout<<sum<<endl;
	for(int i=0;i<(int)ans.size()-1;++i){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

 

C. Trailing Loves (or L'oeufs?)

单独写了戳这里

 

D. Flood Fill

单独写了戳这里

 

E. Arithmetic Progression

bj聚聚的代码

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+5;
int gcd(int a, int b) {
	while (b) {
		int tmp = a;
		a = b;
		b = tmp%b;
	}
	return a;
}
int ask1(int i) {
	cout << "? " << i << endl;
	cout.flush();
	int tmp;
	cin >> tmp;
	return tmp;
}
int ask2(int x) {
	cout << "> " << x << endl;
	cout.flush();
	int tmp;
	cin >> tmp;
	return tmp;
}
bool vis[maxn];
vector<int> vec;
int main() {
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int mx, d, x1;
	int l = 0, r = 1e9;
	int times = 60;
	while (l <= r) {
		int mid = (l+r)/2;
		if (ask2(mid)) {
			mx = mid;
			l = mid+1;
		} else {
			r = mid-1;
		}
		times--;
	}
	mx += 1;
	vec.push_back(mx);
	default_random_engine e(time(0));
	uniform_int_distribution<int> u(1, n);
	int idrange = n;
	while (times-- && idrange--) {
		int index = u(e);
		while (vis[index])
			index = u(e);
		vis[index] = true;
		int tmp = ask1(index);
		vec.push_back(tmp);
	}
	sort(vec.begin(), vec.end());
	d = vec[1]-vec[0];
	for (int i = 2; i < vec.size(); ++i) {
		d = gcd(d, vec[i]-vec[i-1]);
	}
	x1 = mx - (n-1)*d;
	cout << "! " << x1 << " " << d << endl;
	cout.flush();
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值