IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2)



A - Kevin and Arithmetic#

题意#

给定n个整数a1,a2,···,an,和初始化为0的整数s。将ai加到s上,若得到的s是偶数,加1分,然后s。重新排列a,使得分最大化

思路#

详情见代码

代码#

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;

const int mxn = 1e6 + 5;

void solve()
{
	int n, cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a & 1)
		{
			cnt++;
		}
	}
	if (!cnt)
	{
		cout << 1 << endl;
		return;
	}
	if (cnt == n)
	{
		cout << n - 1 << endl;
		return;
	}
	cout << cnt + 1 << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int T = 1;
	cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}


B - Kevin and Arithmetic#

题意#

给定n根一直长度的棍子,问是否能挑4根组成等腰梯形(长方形和正方形也是等腰梯形)。

思路#

找最大腰,然后找一条最小边,这样最优。用A,B,C表示上底边,腰和下底边,则要满足A+2B>C

代码#

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;

const int mxn = 1e6 + 5;

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int A, B, p;
	for (int j = n - 1; j > 0; j--)
	{
		if (a[j] == a[j - 1])
		{
			B = a[j];
			p = j;
			for (int i = 0; i < n; i++)
			{
				if (i == p || i == p - 1)
				{
					continue;
				}
				A = a[i];
				auto q = lower_bound(a.begin(), a.end(), A);
				while (q - a.begin() == i || q - a.begin() == p || q - a.begin() == p - 1)
				{
					q++;
				}
				if (q == a.end() || a[q - a.begin()] >= A + 2 * B)
				{
					continue;
				}
				cout << A << " " << B << " " << B << " " << a[q - a.begin()] << endl;
				return;
			}
		}
	}
	cout << -1 << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int T = 1;
	cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}


C - Kevin and Puzzle#

题意#

n个人站成一排,ai表示第i个人说左边(包括自己),有多少人是骗子(骗子可以说真话也可以说谎)。两个骗子不能相邻。问有多少组合。

思路#

详情见代码

代码#

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;

const int mxn = 2e5 + 5;
const int mod = 998244353;

int dp[mxn][2]; // dp[i][0]表示到第i个人并且他不诚实的方案数
int cnt[mxn]; // cnt[i]表示如果第i个人说谎,[1,i)说谎的人数

void clear(int n)
{
	for (int i = 1; i <= n; i++)
	{
		dp[i][0] = dp[i][1] = 0;
	}
}

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	if (a[1])
	{
		cnt[1] = dp[1][0] = 1;
	}
	else
	{
		dp[1][1] = dp[1][0] = cnt[1] = 1;
	}
	for (int i = 2; i <= n; i++)
	{
		// 当前不诚实
		dp[i][0] = dp[i - 1][1]; // 如果不诚实了,上一个人一定诚实
		cnt[i] = a[i - 1] + 1;
		// 当前诚实
		if (a[i] < i)
		{
			if (a[i] == a[i - 1]) // 上一个人诚实
			{
				dp[i][1] = dp[i - 1][1];
			}
			if (a[i] == cnt[i - 1]) // 上一个人说谎
			{
				dp[i][1] += dp[i - 1][0];
				dp[i][1] %= mod;
			}
		}
	}
	cout << (dp[n][0] + dp[n][1]) % mod << endl;
	clear(n);
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int T = 1;
	cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}


D - Kevin and Numbers#

题意#

给定长度为n的正整数序列a,可以执行以下操作任意次:选择两个数x,y(|xy|1)删除,添加一个数x+y。问能否得到长度为m的序列b

思路#

注意|xy|1这个条件,这让我们可以拆解b——如果bi是偶数,那只能拆成两个bi2;如果bi是奇数,那只能拆成bi2bi+12

代码#

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;

const int mxn = 2e5 + 5;

void solve()
{
	int n, m, A = 0, B = 0;
	cin >> n >> m;
	priority_queue<int> a, b;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		A += x;
		a.push(x);
	}
	for (int i = 0; i < m; i++)
	{
		int x;
		cin >> x;
		B += x;
		b.push(x);
	}
	if (A != B)
	{
		cout << "NO" << endl;
		return;
	}
	while (a.size() && b.size())
	{
		int t = b.top();
		b.pop();
		if (t == a.top())
		{
			a.pop();
		}
		else if (t < a.top())
		{
			cout << "NO" << endl;
			return;
		}
		else
		{
			b.push(t >> 1);
			b.push(t + 1 >> 1);
		}
	}
	if (b.size())
	{
		cout << "NO" << endl;
		return;
	}
	cout << "YES" << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int T = 1;
	cin >> T;
	while (T--)
	{
		solve();
	}

	return 0;
}



比赛链接 https://mirror.codeforces.com/contest/2061

posted @   _SeiI  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示