Codeforces Round #640 (Div. 4)
作者:互联网
题目链接:http://codeforces.com/contest/1352
A
思路:9876拆成9000+800+70+6就行了,其他类似这样拆,注意当某一位为0就不用处理了。
//------------------------------------------------- //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; }View Code
B
思路:根据n和k的奇偶性判断,n是奇数,k是偶数是不能找到k个奇偶性相同的数之和为n的,k>n也是不满足的,然后就是奇奇,偶偶,偶奇的情况,奇奇的话全部一开始k个数全为1,然后剩余的偶数全部加在这k个数的任何一个数,还是奇数,偶偶的话判断2*k和n的大小,<的话一开始全置2,>的话一开始只能全置1,否则不够,剩余的还是加在k个数当中的任何一个即可,偶奇的话也要判断2*k和n的大小,<的话一开始全置2,剩余的再加到其中任何一个,>的话无法找到奇偶性相同的k个数之和为n。
//------------------------------------------------- //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\n"); else if(n%2==0&&k%2==0) { if(2*k<=n) { printf("YES\n"); for(int i=0;i<k-1;i++) printf("2 "); printf("%lld \n",n-2*(k-1)); } else{ printf("YES\n"); for(int i=0;i<k-1;i++) printf("1 "); printf("%lld \n",1+n-k); } } else if(n%2!=0&&k%2!=0){ printf("YES\n"); for(int i=0;i<k-1;i++) { printf("1 "); } printf("%lld \n",1+n-k); } else if(n%2==0&&k%2!=0){ if(2*k<=n){ printf("YES\n"); for(int i=0;i<k-1;i++) printf("2 "); printf("%lld\n",2+n-2*k); } else { printf("NO\n"); } } } return 0; }View Code
C
思路:计算k/(n-1)他与n相乘加上k%(n-1)就行了,注意一下结果是否还能整除n,能的话要减一。
//------------------------------------------------- //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; }View Code
D
待续...
标签:typedef,Created,int,ll,Codeforces,long,640,Div,include 来源: https://www.cnblogs.com/Vampire6/p/12862488.html