1.18
cf 581c
重新自己写了一遍,注意都是0 的时候
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<vector> 6 using namespace std; 7 8 const int maxn = 1e5+5; 9 int n,k; 10 11 struct node{ 12 int x,y; 13 }p[maxn]; 14 15 int cmp(node n1,node n2){ 16 return n1.y < n2.y; 17 } 18 19 int cmp0(node n1,node n2){ 20 return n1.x < n2.x; 21 } 22 23 int a[105]; 24 25 void solve(){ 26 for(int i = 1;i <= n;i++){ 27 int pos = lower_bound(a+1,a+10,p[i].x) - a; 28 if(a[pos] == p[i].x) pos++; 29 p[i].y = a[pos] - p[i].x; 30 // printf("a[%d] = %d p[%d].x = %d\n",pos,a[pos],i,p[i].x); 31 } 32 /* for(int i = 1;i <= n;i++){ 33 printf("p[%d].x = %d y = %d\n",i,p[i].x,p[i].y); 34 }*/ 35 sort(p+1,p+n+1,cmp); 36 int ans = 0; 37 for(int i = 1;i <= n;i++){ 38 if(k >= p[i].y){ 39 ans += (p[i].x + p[i].y)/10; 40 k -= p[i].y; 41 p[i].x = p[i].x + p[i].y; 42 } 43 else { 44 ans += p[i].x/10; 45 } 46 // printf("i = %d k = %d ans = %d\n",i,k,ans); 47 } 48 if(k){ 49 for(int i = 1;i <= n;i++){ 50 int l = 10 - p[i].x/10; 51 int r = k/10; 52 if(r >= l){ 53 ans += l; 54 k = k-l*10; 55 } 56 else{ 57 ans += k/10; 58 k = k%10; 59 } 60 if(k < 10) break; 61 //printf("l = %d r = %d k = %\n",l,r,k); 62 } 63 } 64 printf("%d\n",ans); 65 } 66 67 int main(){ 68 for(int i = 1;i <= 10;i++) a[i] = i*10; 69 a[11] = 100; 70 // freopen("in.txt","r",stdin); 71 // freopen("out.txt","w",stdout); 72 while(scanf("%d %d",&n,&k) != EOF){ 73 for(int i = 1;i <= n;i++){ 74 scanf("%d",&p[i].x); 75 } 76 solve(); 77 } 78 return 0; 79 }
cf 614e
先不理解题解说的 part 是什么意思,,就是所有a[i] 的gcd
然后像题解说的那样构造
1 #include<cstdio> 2 #include<cstring> 3 #include<vector> 4 #include<iostream> 5 #include<algorithm> 6 using namespace std; 7 8 const int maxn = 1e5+5; 9 char s[maxn]; 10 int n,a[maxn],aa[maxn]; 11 12 int gcd(int a,int b){ 13 return (!b) ? a:gcd(b,a%b); 14 } 15 16 void solve(){ 17 int part = a[1]; 18 for(int i = 2;i <= n;i++){ 19 part = gcd(part,a[i]); 20 } 21 for(int i = 1;i <= n;i++){ 22 aa[i] = a[i]/part; 23 } 24 25 if(part%2 == 0){ 26 printf("%d\n",part); 27 vector<char> c; 28 for(int i = 1;i <= n;i++){ 29 for(int j = 1;j <= aa[i];j++){ 30 c.push_back(i+‘a‘-1); 31 } 32 } 33 int flag = 1; 34 for(int i = 1;i <= part;i++){ 35 if(flag){ 36 for(int j = 0;j < c.size();j++){ 37 printf("%c",c[j]); 38 } 39 } 40 else{ 41 for(int j = c.size()-1;j >= 0;j--){ 42 printf("%c",c[j]); 43 } 44 } 45 flag = !flag; 46 } 47 printf("\n"); 48 return; 49 } 50 int ji = 0; 51 for(int i = 1;i <= n;i++){ 52 ji += (aa[i]%2); 53 } 54 if(ji > 1){ 55 puts("0"); 56 for(int i = 1;i <= n;i++){ 57 for(int j = 1;j <= a[i];j++){ 58 char z = i+‘a‘-1; 59 printf("%c",z); 60 } 61 } 62 printf("\n"); 63 } 64 if(ji == 1){ 65 vector<char> l; 66 vector<char> r; 67 int pos; 68 for(int i = 1;i <= n;i++){ 69 if(a[i]%2){ 70 pos = i; 71 break; 72 } 73 } 74 for(int i = 1;i <= n;i++){ 75 if(i == pos) continue; 76 for(int j = 1;j <= aa[i]/2;j++){ 77 l.push_back(i+‘a‘-1); 78 r.push_back(i+‘a‘-1); 79 } 80 } 81 for(int j = 1;j <= aa[pos];j++){ 82 l.push_back(pos+‘a‘-1); 83 } 84 reverse(r.begin(),r.end()); 85 for(int j = 0;j < r.size();j++){ 86 l.push_back(r[j]); 87 } 88 printf("%d\n",part); 89 for(int i = 1;i <= part;i++){ 90 for(int j = 0;j < l.size();j++){ 91 printf("%c",l[j]); 92 } 93 } 94 printf("\n"); 95 } 96 } 97 98 int main(){ 99 while(scanf("%d",&n) != EOF){ 100 for(int i = 1;i <= n;i++){ 101 scanf("%d",&a[i]); 102 } 103 solve(); 104 } 105 return 0; 106 }
时间: 2024-10-12 03:25:11