A. Brain ' s Photos
Exercises
Water's not going to stop.
Code:
#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) memcpy (x,y,sizeof (×))#defineSZ (x) ((int) (x). Size ())#definefor (It,c) for (__typeof ((c). Begin ()) it= (c). Begin (); it!= (c). end (); it++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intmaxn= $;Const intmod=1e9+7;Const intinf=1e9;stringp;Set<string>s;intMain () {S.insert ("C"); S.insert ("M"); S.insert ("Y"); intn,m,flag=0; CIN>>n>>m; for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {cin>>p; if(flag)Continue; if(S.count (p)) flag=1; } if(!flag) cout<<"#Black &white"<<Endl; Elsecout<<"#Color"<<Endl; return 0;}
B.chris and Magic Square
Exercises
English reading problem, understand test instructions is very water
Code:
#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) memcpy (x,y,sizeof (×))#defineSZ (x) ((int) (x). Size ())#definefor (It,c) for (__typeof ((c). Begin ()) it= (c). Begin (); it!= (c). end (); it++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intmaxn=1e5+Ten;Const intmod=1e9+7;Const intinf=1e9+Ten;intV[MAXN],U[MAXN],W[MAXN];Set<int>s;intMain () {intn,m,k,tmp; CIN>>n>>m>>K; for(intI=1; i<=m;i++) cin>>v[i]>>u[i]>>W[i]; for(intI=1; i<=k;i++) {cin>>tmp; S.insert (TMP); } intans=INF; for(intI=1; i<=m;i++){ if((S.count (V[i]) &&!s.count (U[i])) | | (!s.count (V[i]) &&S.count (U[i])) Ans=min (W[i],ans); } if(Ans==inf) cout<<-1<<Endl; Elsecout<<ans<<Endl;}
C. Pythagorean Triples
Exercises
Baidu Check the number of shares on the line ...
Code:
#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) memcpy (x,y,sizeof (×))#defineSZ (x) ((int) (x). Size ())#definefor (It,c) for (__typeof ((c). Begin ()) it= (c). Begin (); it!= (c). end (); it++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intmaxn= $;Const intmod=1e9+7;Const intinf=1e9; LL n,m,a,b,c;intMain () {CIN>>N; if(n<3) cout<<-1<<Endl; Else{ if(n&1) {b= (n*n-1*1LL)/2*1LL; C= (n*n+1*1LL)/2*1LL; } Else{b= (n*n/2-2*1LL)/2*1LL; C= (n*n/2+2*1LL)/2*1LL; } cout<<b<<" "<<c<<Endl; } return 0;}
D. Persistent Bookcase
Exercises
The question of the test code force. Use the Bitset, then simulate on the line.
Note that there are 4 kinds of actions that change the value of a row
Code:
#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) memcpy (x,y,sizeof (×))#defineSZ (x) ((int) (x). Size ())#definefor (It,c) for (__typeof ((c). Begin ()) it= (c). Begin (); it!= (c). end (); it++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intn=1e5+Ten;Const intm=1e3+Ten;Const intmod=1e9+7;Const intinf=1e9+Ten; Bitset<M>bs[n],tmp;intque[n][m],ans[n],cnt;intMain () {intN,m,q,a,b,c; CNT=0; scanf ("%d%d%d",&n,&m,&q); for(intI=1; i<=m;i++) tmp[i]=1; for(intI=1; i<=q;i++) {scanf ("%d%d",&a,&b); if(a==4){ for(intj=1; j<=n;j++) que[i][j]=Que[b][j]; Ans[i]=Ans[b]; Continue; } for(intj=1; j<=n;j++) que[i][j]=que[i-1][j]; Ans[i]=ans[i-1]; intid=que[i-1][b]; if(a==3) {bs[++cnt]=Bs[id]; Ans[i]-=Bs[cnt].count (); BS[CNT]^=tmp; Ans[i]+=Bs[cnt].count (); QUE[I][B]=CNT; } if(a==2) {scanf ("%d",&c); if(bs[id][c]==0)Continue; bs[++cnt]=Bs[id]; BS[CNT][C]=0; Ans[i]--; QUE[I][B]=CNT; } if(a==1) {scanf ("%d",&c); if(bs[id][c]==1)Continue; bs[++cnt]=Bs[id]; BS[CNT][C]=1; Ans[i]++; QUE[I][B]=CNT; } } for(intI=1; i<=q;i++) printf ("%d\n", Ans[i]); return 0; }
Codeforces Round #368 (Div. 2) ABCD