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<<‘\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<<‘\n‘;
41         for(int i=0;i<n;i++) cout<<arr[i%m];
42     }
43     return 0;
44 }

太菜了QAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQAQAQAQAQAQAQAQQAQQAQ

原文地址:https://www.cnblogs.com/pengge666/p/12079429.html

时间: 2024-07-29 06:17:45

Codeforces Round #609 (Div. 2) 【A,B,C】的相关文章

Codeforces Round #436 (Div. 2)【A、B、C、D、E】

Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张卡片上都写有一个数,两个人每人选一个数,每人可以拿的卡片必须写有是自己选的数,问能否选择两个数使得两个人每人拿的卡片数一样多并且能拿光卡片.[就是看输入是不是只有两种数字] //:第一遍我看成字符串包含有选的数字也能拿,,这样写着居然过了..水题水题.. 1 #include<cstdio> 2

Codeforces Round #609 (Div. 2) A-E简要题解

contest链接:https://codeforces.com/contest/1269 A. Equation 题意:输入一个整数,找到一个a,一个b,使得a-b=n,切a,b都是合数 思路:合数非常多,从1开始枚举b,a就是b+n,每次check一下a,b是否是合数,是的话直接输出,break即可 AC代码: 1 #include<iostream> 2 #include<string> 3 #include<vector> 4 #include<cstri

Codeforces Round #609 (Div. 2)E--K Integers(贪心+二分+树状数组+逆序对)

K Integers 参考博客:https://blog.csdn.net/Q755100802/article/details/103664555 [题意] 给定一个1到n的排列,可以交换相邻的两个元素. 现在定义一个函数f(x),表示在原排列中,通过交换操作,形成一个1,2,3....x的排列的子串,需要的最小操作步骤. 子串意味着这个排列必须是相邻的.现在你需要求出f(1),f(2),f(3)......f(n). [分析] 在1~x这几个元素相邻的情况下,因为最后排列不存在逆序对,根据贪

A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 【数学】

题目: Little C loves number ?3? very much. He loves all things about it. Now he has a positive integer nn. He wants to split nn into 3 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 3 integers is a multiple of 3. Help him to fin

C. Enlarge GCD Codeforces Round #511 (Div. 2)【数学】

题目: Mr. F has nn positive integers, a1,a2,-,an. He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers. But this problem is too simple for him, so he does not want to do it by

Codeforces Round #609 (Div. 2)

A 简单题,输出 8n 和9n即可 因为8n是8的倍数,9n是9的倍数 而9n-8n=n成立 #include <iostream> #include <cstdio> using namespace std; int main(){ int n; cin >> n; printf("%d %d\n",9 * n, 8 * n); return 0; } B 给出两个n长的序列和一个m \((a_{i}+x) %m = b_{p}\) 这题我失误了,

Codeforces Round #609 (Div. 2) 题解

Equation Modulo Equality Long Beautiful Integer Domino for Young K Integers Equation \[ Time Limit: 3 s\quad Memory Limit: 256 MB \] 这题做法很多,甚至可以直接暴力判断 view #include <map> #include <set> #include <list> #include <ctime> #include <

Codeforces Round #451 (Div. 2)【A,B,C,D,E】【C题:模拟 D题:尺取+贪心 E题:思维+优先队列维护最值】

特判最后一位即可 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 #define int long long 5 6 signed main(){ 7 int n;cin>>n;int t=n%10; 8 if(t==0) cout<<n; 9 else if(t>5) { 10 cout<<(n+10-t); 11 } 12 else { 13 cout<<(n-t); 14 }

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities【最短路】

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities[最短路] 题目链接:点击打开 题目大意: 在一个国家中有n个城市(城市编号1~n),m条公路和k条铁路,编号为1的城市为首都,为了节约,不需要的铁路需要关闭,问在保证首都到其余所有城市的最短路不变的条件下,最多有多少条铁路是不需要的. 解法: 这个题比较麻烦,保证首都到其余城市的最短路不变,要求出最多有多少条铁路是不需要的,那肯定是从最短路的代码上下手了,我们首先考虑dijkstra算法