题目链接:http://codeforces.com/contest/1352
A
思路:9876拆成9000+800+70+6就行了,其他类似这样拆,注意当某一位为0就不用处理了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//------------------------------------------------- //Created by HanJinyu //Created Time :一 5/ 4 16:56:31 2020 //File Name :632B.cpp //------------------------------------------------- #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn = 200005; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--){ int n; string s; cin>>s; bool flag=false; int ops=0; for(int i=0;i<s.length();i++) { if(s[i]!='0'&&i!=0) { flag=true; ops++; } else if(i==0&&s[i]!='0'){ ops++; } } if(!flag){ cout<<"1"<<endl<<s<<endl; } else { cout<<ops<<endl; for(int i=0;i<s.length();i++){ if(s[i]!='0'){ cout<<s[i]; for(int j=0;j<s.length()-i-1;j++){ cout<<'0'; } cout<<" "; } } cout<<endl; } } return 0; }
B
思路:根据n和k的奇偶性判断,n是奇数,k是偶数是不能找到k个奇偶性相同的数之和为n的,k>n也是不满足的,然后就是奇奇,偶偶,偶奇的情况,奇奇的话全部一开始k个数全为1,然后剩余的偶数全部加在这k个数的任何一个数,还是奇数,偶偶的话判断2*k和n的大小,<的话一开始全置2,>的话一开始只能全置1,否则不够,剩余的还是加在k个数当中的任何一个即可,偶奇的话也要判断2*k和n的大小,<的话一开始全置2,剩余的再加到其中任何一个,>的话无法找到奇偶性相同的k个数之和为n。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//------------------------------------------------- //Created by HanJinyu //Created Time :一 5/ 4 16:56:31 2020 //File Name :632B.cpp //------------------------------------------------- #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn = 200005; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--){ ll n; int k; scanf("%lld%d",&n,&k); if(k>n||(n%2!=0&&k%2==0)) printf("NO "); else if(n%2==0&&k%2==0) { if(2*k<=n) { printf("YES "); for(int i=0;i<k-1;i++) printf("2 "); printf("%lld ",n-2*(k-1)); } else{ printf("YES "); for(int i=0;i<k-1;i++) printf("1 "); printf("%lld ",1+n-k); } } else if(n%2!=0&&k%2!=0){ printf("YES "); for(int i=0;i<k-1;i++) { printf("1 "); } printf("%lld ",1+n-k); } else if(n%2==0&&k%2!=0){ if(2*k<=n){ printf("YES "); for(int i=0;i<k-1;i++) printf("2 "); printf("%lld ",2+n-2*k); } else { printf("NO "); } } } return 0; }
C
思路:计算k/(n-1)他与n相乘加上k%(n-1)就行了,注意一下结果是否还能整除n,能的话要减一。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//------------------------------------------------- //Created by HanJinyu //Created Time :一 5/ 4 16:56:31 2020 //File Name :632B.cpp //------------------------------------------------- #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn = 200005; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--){ ll n,k; cin>>n>>k; ll mm=k/(n-1); ll nn=k%(n-1); ll result=mm*n+nn; if(result%n==0) cout<<result-1<<endl; else cout<<result<<endl; } return 0; }
D
思路:用list前后遍历就好了,每吃掉就pop一个,做题太慢,这题题目都没看,比赛就结束了。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//------------------------------------------------- //Created by HanJinyu //Created Time :一 5/ 4 16:56:31 2020 //File Name :632B.cpp //------------------------------------------------- #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn = 200005; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); list<int>l; int a; for(int i=0;i<n;i++){ scanf("%d",&a); l.push_back(a); } int Alice=0,Bob=0,foot=0,BB=0; for(int i=0;i<i+l.size();i++){ int A1=0,B1=BB; bool flag=false,flag1=false; while(A1<=B1){ if(l.size()>0){ Alice+=l.front(); A1+=l.front(); l.pop_front(); flag=true; } else { break; } } if(flag)foot++; B1=0; while(B1<=A1){ if(l.size()>0){ Bob+=l.back(); B1+=l.back(); l.pop_back(); flag1=true; } else { break; } } if(flag1)foot++; BB=B1; } printf("%d %d %d ",foot,Alice,Bob); } return 0; } //input //1 //3 //8 6 10 //output //3 14 10