Loading

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,B\)\(A\)里有\(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 @ 2025-02-14 22:59  _SeiI  阅读(70)  评论(0)    收藏  举报