Codeforces Round #368 (Div. 2) ABCD
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #368 (Div. 2) ABCD相关的知识,希望对你有一定的参考价值。
A. Brain‘s Photos
题解:
水得不要不要的
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef pair<int,int> P; const double eps=1e-9; const int maxn=200; const int mod=1e9+7; const int INF=1e9; string p; set<string> s; int main(){ s.insert("C"); s.insert("M"); s.insert("Y"); int n,m,flag=0; cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ cin>>p; if(flag) continue; if(s.count(p)) flag=1; } if(!flag) cout<<"#Black&White"<<endl; else cout<<"#Color"<<endl; return 0; }
B.Chris and Magic Square
题解:
英语阅读题,看懂题意就很水了
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef pair<int,int> P; const double eps=1e-9; const int maxn=1e5+10; const int mod=1e9+7; const int INF=1e9+10; int v[maxn],u[maxn],w[maxn]; set<int> s; int main(){ int n,m,k,tmp; cin>>n>>m>>k; for(int i=1;i<=m;i++) cin>>v[i]>>u[i]>>w[i]; for(int i=1;i<=k;i++){ cin>>tmp; s.insert(tmp); } int ans=INF; for(int i=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; else cout<<ans<<endl; }
C. Pythagorean Triples
题解:
百度一下勾股数就行了。。。
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef pair<int,int> P; const double eps=1e-9; const int maxn=200; const int mod=1e9+7; const int INF=1e9; LL n,m,a,b,c; int main(){ 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
题解:
考验码力的题目。。用上bitset,然后模拟就行了。
注意到一点,4种操作,更改的都是一行的值
代码:
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)) #define SZ(x) ((int)(x).size()) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef pair<int,int> P; const double eps=1e-9; const int N=1e5+10; const int M=1e3+10; const int mod=1e9+7; const int INF=1e9+10; bitset<M> bs[N],tmp; int que[N][M],ans[N],cnt; int main(){ int n,m,q,a,b,c; cnt=0; scanf("%d%d%d",&n,&m,&q); for(int i=1;i<=m;i++) tmp[i]=1; for(int i=1;i<=q;i++){ scanf("%d%d",&a,&b); if(a==4){ for(int j=1;j<=n;j++) que[i][j]=que[b][j]; ans[i]=ans[b]; continue; } for(int j=1;j<=n;j++) que[i][j]=que[i-1][j]; ans[i]=ans[i-1]; int id=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(int i=1;i<=q;i++) printf("%d\n",ans[i]); return 0; }
以上是关于Codeforces Round #368 (Div. 2) ABCD的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #368 (Div. 2) ABCD
Codeforces Round #368 (Div. 2)
Codeforces Round #368 (Div. 2) D. Persistent Bookcase 主席树套bitset
Codeforces Round #436 E. Fire(背包dp+输出路径)