Codeforces Round 893 (Div. 2) A ~ C

比赛链接

A. Buttons

 博弈、最优策略一定是先去按都能按的按钮,按完之后再按自己的。

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

int main()
{
	IOS
	int _;
	cin >> _;
	while(_ --)
	{
		ll a, b, c;
		cin >> a >> b >> c;
		a += (c + 1) / 2, b += c / 2;
		if(a > b)cout << "First" << endl;
		else cout << "Second" << endl;
	}
	
	return 0;
}

B. The Walkway

 阅读理解,难点在英语。

每隔d位至少要吃一次饼干,其实可以看商人与商人之间的距离是多少,商人与商人之间的距离-1除d就是这段距离内吃的饼干数,可以用一个数组来记录每个商人前有多少个空位。

然后枚举计算删掉每一个商人后的贡献就好了。

注意第一个商人在不在第一个长椅旁这里需要多考虑一下,记得特判。

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

const int N = 100010;

int a[N], b[N];

void solve()
{
	int n, m, d;
	cin >> n >> m >> d;
	for(int i = 1; i <= m; i ++)
	{
		cin >> a[i];
	}
	
	a[0] = 0, b[0] = 0;
	if(a[1] == 1)b[1] = 0;
	else b[1] = a[1] - 2;
	
	for(int i = 2; i <= m; i ++)
	{
		b[i] = a[i] - a[i - 1] - 1;
	}
	b[m + 1] = n - a[m];
	
	map<int, int> mp;
	
	ll ans = 0;
	if(a[1] != 1)ans ++;
	for(int i = 1; i <= m; i ++)
	{
		ans ++;
		ans += b[i] / d;
	}
	ans += b[m + 1] / d;
	
	int maxn = 0;
	for(int i = 2; i <= m; i ++)
	{
		int A = b[i] / d + b[i + 1] / d + 1;
		int B = (b[i] + b[i + 1] + 1) / d;
		maxn = max(maxn, A - B);
		mp[A - B] ++;
	}
	if(a[1] == 1)
	{
		int A = 1 + b[2] / d;
		int B = 1 + b[2] / d;
		maxn = max(maxn, A - B);
		mp[A - B] ++;
	}
	else
	{
		int i = 1;
		int A = b[i] / d + b[i + 1] / d + 1;
		int B = (b[i] + b[i + 1] + 1) / d;
		maxn = max(maxn, A - B);
		mp[A - B] ++;
	}
	
	cout << ans - maxn << ' ' << mp[maxn] << endl;
}

int main()
{
	IOS
	int _;
	cin >> _;
	while(_ --)
	{
		solve();
	}
	
	return 0;
}

C. Yet Another Permutation Problem

贪心。

既然要求d的种类多,那就尽可能的增加d中数字的种类数,怎么增加呢?从小往大加就好了,比如说2后面放4,3后面放6,4后面放8,就像这样连续下去d中的种类数一定是最多的。

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

const int N = 100010;

bool st[N];

void solve()
{
	memset(st, false, sizeof st);
	int n;
	cin >> n;
	st[1] = true;
	cout << 1 << ' ';
	for(int i = 2; i <= n / 2; i ++)
	{
		if(st[i])continue;
		int j = i;
		while(j <= n)
		{
			st[j] = true;
			cout << j << ' ';
			j *= 2;
		}
	}
	for(int i = 1; i <= n; i ++)
	{
		if(!st[i])cout << i << ' ';
	}
	cout << endl;
}

int main()
{
	IOS
	int _;
	cin >> _;
	while(_ --)
	{
		solve();
	}
	
	return 0;
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值