Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
A. Golden Plate
水题
B. Curiosity Has No Limits(构造)
题意:给出一个长度为n-1的序列a和一个长度为n-1的序列b,问能否构造出一个长度为n的序列t,使得t(i)|t(i+1)=a(i), t(i)&t(i+1)=b(i),其中每个序列的元素都大于等于0小于等于3.
题解:首先要找到一个规律:(a&b+a|b)= (a+b)然后枚举t(1),剩下的就能确定了,每个再判断是否可行即可。
代码:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int n; int a[100010], b[100010], t[100010]; int main(){ scanf("%d", &n); for(int i = 1; i<=n-1; i++){ scanf("%d", &a[i]); } for(int i = 1; i<=n-1; i++){ scanf("%d", &b[i]); } int now = 1; for(int i = 0; i<=3; i++){ t[1] = i; now = 1; for(int j = 1; j<=n-1; j++){ int tmp = a[j]+b[j]-t[j]; if(tmp<=3 && (t[j]|tmp) == a[j] && (t[j]&tmp) == b[j]){ t[j+1] = tmp; now = j+1; } else{ break; } } if(now == n){ break; } } if(now == n){ printf("YES\n"); for(int i = 1; i<=n; i++){ if(i!=1) printf(" "); printf("%d", t[i]); } printf("\n"); } else{ printf("NO\n"); } return 0; }
C. Cram Time
题意:给出两个数a,b。把1-n放到两组中,每组的和不能大于a和b,且两组的元素个数加起来最大
题解:计算出a+b 以及 最大的t,t*(t+1)/2<=a+b,这样就能放t个数,然后贪心从大到小放
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; int a, b; vector<int> G; int vis[1000010]; int main(){ scanf("%d %d", &a, &b); int sum = a+b; int t; for(t = 1; t<=100010; t++){ if((long long)t*(t+1)/2>(long long)sum){ t--; break; } } int m = a; int tmp = 0; for(int i = t; i>=1; i--){ if(tmp+i<=m){ G.push_back(i); vis[i] = 1; tmp+=i; } } cout<<G.size()<<endl; for(int i = 0; i<G.size(); i++){ if(i!=0) cout<<" "; cout<<G[i]; } cout<<endl; cout<<t-G.size()<<endl; bool flag = true; for(int i = 1; i<=t; i++){ if(!vis[i]){ if(flag == false) cout<<" "; cout<<i; flag = false; } } cout<<endl; return 0; }