codeforces 368(div 2)前三题
来源:互联网 发布:骚男的衣服淘宝店 编辑:程序博客网 时间:2024/06/08 00:51
第一题
很多人没看到G,被坑了
#include<cstdio>#include<iostream>int main(){ int n,m; char x,y; scanf("%d%d\n",&n,&m); bool ok = 1; for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++){ scanf("%c%c",&x,&y); if (x=='C'||x=='M'||x=='Y')ok = 0; } } if (ok)puts("#Black&White"); else puts("#Color");}
第二题,
a[i]=1表示i位置是个仓库
然后按边的权值排序,找一条边两个点一个是仓库一个不是仓库的
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int N=1e5 + 10;struct Edge{ int x,y,w; Edge(){} Edge(int _x,int _y,int _w):x(_x),y(_y),w(_w){} bool operator < (Edge a)const { return w < a.w ; }}edges[N];int a[N];int main(){ int n,m,k,x,y,z; scanf("%d%d%d",&n,&m,&k); for (int i=1;i<=m;i++){ scanf("%d%d%d",&x,&y,&z); edges[i]=Edge(x,y,z); } if (k==0)puts("-1"); else { memset(a,0,sizeof(a)); for (int i=1;i<=k;i++){ scanf("%d",&x);a[x]=1; } sort(edges+1,edges+m+1); int ans = -1; for (int i=1;i<=m;i++){ if (a[edges[i].x]^a[edges[i].y]){ ans = edges[i].w;break; } } printf("%d\n",ans); } return 0;}
第三题
找勾股数。。。分类讨论就行了
#include<cstdio>#include<iostream>using namespace std;int main(){ long long n; cin >> n; if (n==1 ||n==2 )puts("-1"); else { if (n&1){ n *= n ; printf("%I64d %I64d\n",(n-1)>>1,(n+1)>>1); } else { n >>= 1 ; printf("%I64d %I64d\n",n*n-1,n*n+1); } } return 0;}
第四题
听说是主席树
可持久化数据结构
承旭老师说rope可以秒,
http://blog.csdn.net/iamzky/article/details/38348653
暴力修改版本的,,,TLE的死死的
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<ext/rope>using namespace std;using namespace __gnu_cxx;const int N=1e5 + 10;struct node{ int pos,num; string a; node(){} node(int x,int y,string st){ pos=x,num=y,a=st; }}bo;rope <node> *book[N];int ans[N];int main(){ //freopen("fuck.in","r",stdin); int n,m,q,x,y,ord,tot=0; scanf("%d%d%d",&n,&m,&q); string zero = ""; for (int i=1;i<=m;i++)zero+="0"; book[0]=new rope<node>(); book[0]->push_back(node(0,0,"")); for (int i=1;i<=n;i++) book[0]->push_back(node(i,0,zero)); for (int ti=1;ti<=q;ti++){ book[ti] = new rope <node>(*book[ti-1]); ans[ti] = ans[ti-1]; scanf("%d%d",&ord,&x); if (ord==1){ scanf("%d",&y); bo = book[ti]->at(x); if (bo.a[y-1]=='0'){ bo.a[y-1]='1'; bo.num++; book[ti]->replace(x,bo); ans[ti]++; } }else if (ord==2){ scanf("%d",&y); bo = book[ti]->at(x); if (bo.a[y-1]=='1'){ bo.a[y-1]='0'; bo.num--; book[ti]->replace(x,bo); ans[ti]--; } }else if (ord==3){ bo = book[ti]->at(x); for (int i=0;i<m;i++){ bo.a[i]=(bo.a[i]=='1')?'0':'1'; } bo.num = m - bo.num; book[ti]->replace(x,bo); bo = book[ti]->at(0); ans[ti] += m - bo.num*2 ; }else if (ord==4){ book[ti]= book[x]; ans[ti] = x; } printf("%d\n",ans[ti]); } return 0;}
承旭老师改出个优雅的修改个版本的
MLE了
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<ext/rope>using namespace std;using namespace __gnu_cxx;const int N=1e5+5,M=1e3+5;struct node{ int num; bool a[M],re; node(){}}bo;rope <node> *book[N];int ans[N];int main(){ //freopen("fuck.in","r",stdin); int n,m,q,x,y,ord; book[0]=new rope<node>(); scanf("%d%d%d",&n,&m,&q); for (int i=0;i<n;i++) book[0]->insert(i,bo); for (int ti=1;ti<=q;ti++){ scanf("%d%d",&ord,&x); if (ord==4){ book[ti] = new rope <node>(*book[x]); ans[ti]=ans[x]; }else{ book[ti] = new rope <node>(*book[ti-1]); ans[ti]=ans[ti-1]; } if (ord==1){ scanf("%d",&y); bo=book[ti]->at(x-1); if (bo.a[y-1]^bo.re==0){ bo.a[y-1]^=1; bo.num ++; book[ti]->replace(x-1,bo); ans[ti]++; } } if (ord==2){ scanf("%d",&y); bo=book[ti]->at(x-1); if (bo.a[y-1]^bo.re==1){ bo.a[y-1]^=1; bo.num --; book[ti]->replace(x-1,bo); ans[ti]--; } } if (ord==3){ bo=book[ti]->at(x-1); bo.re^=1; ans[ti]+=m - bo.num*2; bo.num = m - bo.num; book[ti]->replace(x-1,bo); } printf("%d\n",ans[ti]); } return 0;}
搞出个树套树
TLE,要疯了
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<ext/rope>using namespace std;using namespace __gnu_cxx;const int N=1e5 + 10,M=10e3+5;rope <rope<bool>* > *book[N];rope<bool> *tmp,*re[N];rope<int> *num[N];int ans[N];int main(){ // freopen("1.in","r",stdin); // freopen("1.out","w",stdout); int n,m,q,x,y,ord; book[0]=new rope<rope<bool>* >(); tmp=new rope<bool>(); num[0]=new rope<int>(); re[0]=new rope<bool>(); scanf("%d%d%d",&n,&m,&q); for (int i=0;i<m;i++) tmp->insert(i,false); for (int i=0;i<n;i++){ tmp=new rope<bool>(*tmp); book[0]->insert(i,tmp); num[0]->insert(i,0); re[0]->insert(i,false); } for (int ti=1;ti<=q;ti++){ scanf("%d%d",&ord,&x); // printf("%d: %d %d\n",ti,ord,x); if (ord==4){ book[ti] = new rope <rope<bool>* >(*book[x]); num[ti] = new rope<int>(*num[x]); re[ti] = new rope<bool>(*re[x]); ans[ti]=ans[x]; }else{ book[ti] = new rope <rope<bool>* >(*book[ti-1]); num[ti] = new rope<int>(*num[ti-1]); re[ti] = new rope<bool>(*re[ti-1]); ans[ti]=ans[ti-1]; } if (ord==1){ scanf("%d",&y); tmp=book[ti]->at(x-1); bool f=tmp->at(y-1),flag=re[ti]->at(x-1); if (f^flag==0){ tmp=new rope<bool>(*tmp); f^=1; tmp->replace(y-1,f); book[ti]->replace(x-1,tmp); int nu=num[ti]->at(x-1); nu++; num[ti]->replace(x-1,nu); ans[ti]++; } } if (ord==2){ scanf("%d",&y); tmp=book[ti]->at(x-1); bool f=tmp->at(y-1),flag=re[ti]->at(x-1); if (f^flag==1){ tmp=new rope<bool>(*tmp); f^=1; tmp->replace(y-1,f); book[ti]->replace(x-1,tmp); int nu=num[ti]->at(x-1); nu--; num[ti]->replace(x-1,nu); ans[ti]--; } } if (ord==3){ re[ti]->replace(x-1,re[ti]->at(x-1)^1); //printf("%d %d\n",bo.num,bo.cnt); ans[ti]+=m - num[ti]->at(x-1)*2; num[ti]->replace(x-1,m-num[ti]->at(x-1)); } /* for (int i=0;i<n;i++){ tmp=book[0]->at(i); for (int j=0;j<m;j++){ bool f=tmp->at(j); printf("%d ",f^re[0]->at(i)); } puts(""); }*/ printf("%d\n",ans[ti]); } return 0;}
丧心病狂的STL
http://tieba.baidu.com/p/2215390730
0 0
- codeforces 368(div 2)前三题
- 【codeforces】Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (DIV 2)
- Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div. 2)
- codeforces #368 div.2B
- Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div.2)
- Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div. 2)
- Codeforces Round #368 (Div. 2)
- Codeforces Round #190 (Div. 2前三题)
- Codeforces Round #368 (Div. 2) C
- Codeforces Round #368 (Div. 2) Bakery
- iOS面试题-持续更新
- Android高级索引以及搜索使用场景
- 【模拟】Codeforces 704A & 705C Thor
- 左值与右值的区别
- ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量
- codeforces 368(div 2)前三题
- 自定义控件之动态进度View
- Java集合---HashSet的源码分析
- TortoiseGit密钥设置
- DOM节点
- 单点登录SSO学习小结
- 默认readline切换为vi
- L3-008. 喊山-PAT团体程序设计天梯赛GPLT(广度优先搜索)
- Windows窗口消息循环中TranslateAcclerator的理解