Codeforces Round 1004 (Div. 2)



A - Adjacent Digit Sums#

题意#

问是否存在一个n使得S(n+1)=S(n)+1,其中S(x)表示x的数位和

思路#

代码#

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

const int mxn = 5e5 + 5;

void solve()
{
	int x, y;
	cin >> x >> y;
	if (x + y - 1 > 0 && (x + y - 1) % 9 == 0)
	{
		cout << "YES" << endl;
		return;
	}
	cout << "NO" << endl;
}

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

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

	return 0;
}

B - Two Large Bags#

题意#

最初有两个袋子A,BA里有n个球,B为空。每个球上有一个正整数。执行两个操作任意次:将A中的1个球移入b中、从A中选择一个B中也有的球并让这个球的数值+1。问能否使得两个袋子中的球相同

思路#

球到B中就无法改变,因此在把球移入B中时必须保证至少还有1个相同的球在A中。我们尽可能地进行操作2,即对于相同的球只保留2个分别放入A,B,其他的统统+1,检查是否有只有1个的球以及最后一种球是否是奇数即可(多余的数量都转移到最后一种了)

代码#

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

const int mxn = 5e5 + 5;

void solve()
{
	int n;
	cin >> n;
	vector<int> cnt(n + 1);
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		cnt[x]++;
	}
	for (int i = 1; i < n; i++)
	{
		if (cnt[i] == 1)
		{
			cout << "NO" << endl;
			return;
		}
		cnt[i + 1] += max(0LL, cnt[i] - 2);
	}
	if (cnt[n] & 1)
	{
		cout << "NO" << endl;
		return;
	}
	cout << "YES" << endl;
}

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

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

	return 0;
}

C - Devyatkino#

题意#

给定n,每次运算可以将只含9的十进制数加到n上。求使n中出现7需要的最小运算次数

思路#

代码#

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

const int mxn = 5e5 + 5;

void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i <= 9; i++)
	{
		string s = to_string(n - i);
		int maxn = 0;
		for (auto& j : s)
		{
			if (j <= '7')
			{
				maxn = max(maxn, (int)(j - '0'));
			}
		}
		if (i >= 7 - maxn)
		{
			cout << i << endl;
			return;
		}
	}
}

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

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

	return 0;
}


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

posted @   _SeiI  阅读(48)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示