本文最后更新于 2025年2月17日 晚上
1004(div 2)
https://codeforces.com/contest/2067
https://codeforces.com/blog/entry/139415?locale=en
A
思路:感觉找规律做。想半天规律,觉得a每一位都是9且b是1时,或者a最后一位不是9且b=a+1时,为yes;其余为no。但显而易见错了。每位数字之和怎么算,唉
如果n的各位数字相加末尾不是9(n是9的倍数时,各位相加数字结尾是9),那么s(n+1)=s(n)+1。如果n各位数字之和末尾是9,需要加1后再减去9,因为9进位变成了0,s(n+1)=s(n)+1-9k。可以归为一种情况,判断条件可以写为s(n)+1-s(n+1)%9==0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include<bits/stdc++.h> using namespace std;
void solve() { int x,y;cin>>x>>y; if(x+1>=y&&(x+1-y)%9==0) cout<<"Yes"<<'\n'; else cout<<"No"<<'\n'; }
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt;cin>>tt; while(tt--) { solve(); } return 0; }
|
B
思路:仅能想到可以分成偶数组,每组都有偶数个,可以yes;分成两组,每组奇数个,no。唉,想不出来
对数组进行排序,第一个数放入第二个袋子后,第二个袋子中的数不能再进行改变,所以放入第二个袋子后,第一个袋子中要有一个相同的数字,被锁住,不能再对它进行操作,如果第二个数字和第一个数字不相等,直接错误。
第一步操作只能选1,将排序后最小的第一个数放入第二个袋子,后面的数可以选两种操作。还是两个数字分成一组进行操作,如果不相等,看是否可以进行操作二,相等就进行操作1,直到遍历一遍。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include<bits/stdc++.h> using namespace std; 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 mx=0; for(int i=0;i<n;i+=2) { if(max(mx,a[i])!=max(mx,a[i+1])) { cout<<"No"<<'\n'; return; } else { mx=max(mx,a[i])+1; } } cout<<"Yes"<<'\n'; }
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt;cin>>tt; while(tt--) { solve(); } return 0; }
|
C
思路: 每次加9肯定能得到一个含7的。第一次每次加9,直到含7;第二次每次加99;第三次每次加999;直到等于位数
想个垃圾代码还错了
只看每位数字,每位数字在加9次9之后都会完成一次从1到9的循环,其中一定会出现7。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include<bits/stdc++.h> using namespace std;
void solve() { int n;cin>>n; for(int l=0;l<=9;l++) { string s=to_string(n-l); int md=0; for(auto c:s) { if(c<'7') { md=max(md,c-'0'); } } if(l>=7-md) { cout<<l<<'\n'; return; } } }
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt;cin>>tt; while(tt--) { solve(); } return 0; }
|
D
思路:完全没思路