Codeforces Round #609 (Div. 2) A,B,C
Posted pengge666
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #609 (Div. 2) A,B,C相关的知识,希望对你有一定的参考价值。
题意:给一个n<=1e7,找两个合数a和b使得a-b的差为n。
构造a=3n,b=2n,必含有公因子n,只有当n是1的时候是特例。
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 #define int long long 5 #define inf 0x3f3f3f3f3f3f 6 #define N 300009 7 int arr[]={2,3,5,7,13}; 8 signed main(){ 9 int n;scanf("%lld",&n); 10 if(n==1){ 11 cout<<"9 8"; 12 return 0; 13 } 14 cout<<9*n<<" "<<8*n; 15 return 0; 16 }
题意:给一个序列a,一个序列b,把这两个序列任意排序,然后使得对应位置的差在模意义下相等。
思路:排序+变相的尺取
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 #define int long long 5 #define inf 0x3f3f3f3f3f3f3f3f3f3f3f3f3f 6 #define N 200090 7 int a[N],b[N],c[N]; 8 int n,m; 9 int ok(int k){ 10 for(int i=1;i<=n;i++){ 11 c[i]=(k+a[i])%m; 12 } 13 sort(c+1,c+1+n); 14 int f=1; 15 for(int i=1;i<=n;i++){ 16 if(b[i]!=c[i]){ 17 f=0; 18 return f; 19 } 20 } 21 return f; 22 } 23 signed main(){ 24 cin>>n>>m; 25 for(int i=1;i<=n;i++) cin>>a[i]; 26 for(int i=1;i<=n;i++) cin>>b[i]; 27 sort(b+1,b+1+n); 28 int minx=inf; 29 for(int i=1;i<=n;i++){ 30 int temp=0; 31 if(a[i]>b[1]){ 32 temp=m-(a[i]-b[1]); 33 }else{ 34 temp=abs(a[i]-b[1]); 35 } 36 if(ok(temp)){ 37 minx=min(minx,temp); 38 } 39 } 40 cout<<minx; 41 return 0; 42 }
题意:给一个n位10进制数字串s(首位不为0),构造一个数字串t(首位不为0),使得t串是有周期k,且t串>=s串,且t串最小。
直接按题意模拟。
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define int long long 4 #define N 300500 5 int ans[N],arr[N],Temp[N]; 6 signed main(){ 7 int n,m; 8 cin>>n>>m; 9 string str; 10 cin>>str; 11 for(int i=0;i<str.size();i++) arr[i]=(str[i]-‘0‘); 12 int f=1; 13 for(int i=m;i<n;i++){ 14 if((str[i%m]-‘0‘)>(str[i]-‘0‘)){ 15 break; 16 } 17 if((str[i%m]-‘0‘)<(str[i]-‘0‘)){ 18 f=0; 19 break; 20 } 21 } 22 if(f){ 23 cout<<n<<‘ ‘; 24 for(int i=0;i<n;i++) cout<<(str[i%m]-‘0‘); 25 }else{ 26 int cnt=0; 27 for(int i=m-1;i>=0;i--){ 28 Temp[cnt++]=(str[i]-‘0‘); 29 } 30 Temp[0]=Temp[0]+1; 31 for(int i=0;i<=m;i++){ 32 int x=Temp[i]%10; 33 int y=Temp[i]/10; 34 Temp[i]=x; 35 Temp[i+1]=Temp[i+1]+y; 36 } 37 for(int i=0;i<m;i++){ 38 arr[i]=Temp[m-i-1]; 39 } 40 cout<<n<<‘ ‘; 41 for(int i=0;i<n;i++) cout<<arr[i%m]; 42 } 43 return 0; 44 }
太菜了QAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQ
以上是关于Codeforces Round #609 (Div. 2) A,B,C的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #609 (Div. 2)
Codeforces Round #609 (Div. 2)--B.Modulo Equality