Codeforces Round #575 (Div. 3)
A
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+100; int n; ll a,sum=0; int main(){ cin >> n; while(n--){ sum=0; for(int i=0;i<3;i++){ cin >> a; sum += a; } cout << sum/2ll << endl; } return 0; }
B
注意最后一个必须输出n
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5+100; int q; int n,k; int a[N]; int vis[N]; int res[N]; int main(){ cin >> q; while(q--){ cin >> n >> k; memset(vis,0,sizeof(int)*(n+1)); for(int i=0;i<n;i++){ cin >> a[i]; } int flag = 0; ll sum =0 ; int cnt = 0; for(int i=0;i<n;i++){ sum += a[i]; if(!flag && sum%2 == 1){ cnt ++; flag = 1; vis[i] = 1; } else if(flag && sum%2==0){ cnt++; flag = 0; vis[i] =1; } } if(cnt<k){ cout << "NO "; } else{ if(cnt%2!=k%2){ cout << "NO "; } else{ cout << "YES "; int pp=1; res[pp] = n; for(int i=n-2;i>=0;i--){ if(vis[i]){ pp++; if(vis[n-1])res[pp] = i+1; else res[pp] = i; } if(pp == k) break; } for(int i=k;i>=1;i--){ cout << res[i] << (i==1?" ":" "); } } } } return 0; }
C
根据每个机器人的移动范围,不断缩小所有机器人可达范围
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+100; int q; int n; int x[N],y[N]; int f[N][4]; int main(){ scanf("%d",&q); while(q--){ scanf("%d",&n); int r=1e5,l=-1e5,b=1e5,u=-1e5; for(int i=1;i<=n;i++){ scanf("%d%d",&x[i],&y[i]); for(int j=0;j<4;j++){ scanf("%d",&f[i][j]); } if(f[i][0]==0) l=max(l,x[i]); if(f[i][1]==0) b=min(b,y[i]); if(f[i][2]==0) r=min(r,x[i]); if(f[i][3]==0) u=max(u,y[i]); } if(l>r||u>b){ cout << "0 "; } else{ cout << "1 " << l << " " << u << endl; } } return 0; }