Codeforces Round 1004 (Div. 2)
A - Adjacent Digit Sums#
题意#
问是否存在一个
使得 ,其中 表示 的数位和
思路#
代码#
点击查看代码
#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#
题意#
最初有两个袋子
, 里有 个球, 为空。每个球上有一个正整数。执行两个操作任意次:将 中的 个球移入 中、从 中选择一个 中也有的球并让这个球的数值 。问能否使得两个袋子中的球相同
思路#
球到
中就无法改变,因此在把球移入 中时必须保证至少还有 个相同的球在 中。我们尽可能地进行操作 ,即对于相同的球只保留 个分别放入 ,其他的统统 ,检查是否有只有 个的球以及最后一种球是否是奇数即可(多余的数量都转移到最后一种了)
代码#
点击查看代码
#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#
题意#
给定
,每次运算可以将只含 的十进制数加到 上。求使 中出现 需要的最小运算次数
思路#
代码#
点击查看代码
#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
分类:
CodeForces
标签:
思维
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】