Codeforces Round #354 (Div. 2)
来源:互联网 发布:疯狂java讲义阅读 编辑:程序博客网 时间:2024/05/16 06:34
A Nicholas and Permutation
题意:给你一个大小为n的数组,保证数组里的数是1-n.可以任意交换一次位置,求1的位置和n的位置的最大差.
/************************************************************************* File Name: cf_A.cpp ID: obsoles1 PROG: LANG: C++ Mail: 384099319@qq.com Created Time: 三 5/25 23:08:09 2016 ************************************************************************/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<map>#include<queue>#include<stack>#include<cmath>#include<cctype>#include<ctime>#include<cstdlib>#include<string>#include<vector>#include<set>#include<bitset>#define Max(x,y) ((x)>(y)?(x):(y))#define Min(x,y) ((x)<(y)?(x):(y))#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))#define ll long long#define Mem0(x) memset(x,0,sizeof(x))#define Mem1(x) memset(x,-1,sizeof(x))#define MemX(x) memset(x,0x3f,sizeof(x))#define pb push_backusing namespace std;const int N=110;int pos[N];int main(){ int n,x,i; scanf("%d",&n); for(i=1;i<=n;++i){ scanf("%d",&x); pos[x]=i; } int ans; if(pos[1]==1 || pos[1]==n || pos[n]==1 || pos[n]==n)ans=n-1; else ans=Max(Max(Abs(pos[1],n),Abs(pos[1],1)),Max(Abs(pos[n],n),Abs(pos[n],1))); //if(ans<0)ans=-ans; //ans++; //cout<<"ans="<<ans<<endl; //if((pos[1]!=1 && pos[1]!=n) || (pos[n]!=1 && pos[n]!=n))ans++; printf("%d\n",ans);}
B Pyramid of Glasses
题意:宴会上金字塔酒杯,给出n层数,t时间.第一秒能灌满顶层的杯子,之后每过1s,溢出的部分往下流.问t时间后灌满的杯子有几个.
/************************************************************************* File Name: cf_B.cpp ID: obsoles1 PROG: LANG: C++ Mail: 384099319@qq.com Created Time: 三 5/25 23:52:58 2016 ************************************************************************/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<map>#include<queue>#include<stack>#include<cmath>#include<cctype>#include<ctime>#include<cstdlib>#include<string>#include<vector>#include<set>#include<bitset>#define Max(x,y) ((x)>(y)?(x):(y))#define Min(x,y) ((x)<(y)?(x):(y))#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))#define ll long long#define Mem0(x) memset(x,0,sizeof(x))#define Mem1(x) memset(x,-1,sizeof(x))#define MemX(x) memset(x,0x3f,sizeof(x))#define pb push_backusing namespace std;const int N=15;int bot[N][N];bool f[N][N];int main(){ int n,t,i,j,ans; scanf("%d%d",&n,&t); ans=0; bot[1][1]=2048*t; for(i=1;i<=n;++i){ for(j=1;j<=i;++j){ //cout<<"t="<<k<<endl; if(bot[i][j]>=2048){ bot[i+1][j]+=(bot[i][j]-2048)/2; bot[i+1][j+1]+=(bot[i][j]-2048)/2; ans++; //cout<<"bot["<<i+1<<"]["<<j<<"]="<<bot[i+1][j]<<endl; //cout<<"bot["<<i+1<<"]["<<j+1<<"]="<<bot[i+1][j+1]<<endl; } } } printf("%d\n",ans);}
C Vasya and String
题意:给一个只含有a,b的字符串,给你为n长度的字符串,可以翻转m个位置(即a->b,b->a),问最长相同的字母的连续子串长度.
/************************************************************************* File Name: cf_C.cpp ID: obsoles1 PROG: LANG: C++ Mail: 384099319@qq.com Created Time: 三 5/25 23:32:36 2016 ************************************************************************/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<map>#include<queue>#include<stack>#include<cmath>#include<cctype>#include<ctime>#include<cstdlib>#include<string>#include<vector>#include<set>#include<bitset>#define Max(x,y) ((x)>(y)?(x):(y))#define Min(x,y) ((x)<(y)?(x):(y))#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))#define ll long long#define Mem0(x) memset(x,0,sizeof(x))#define Mem1(x) memset(x,-1,sizeof(x))#define MemX(x) memset(x,0x3f,sizeof(x))#define pb push_backusing namespace std;const int N=1e5+10;char s[N];int pre_a[N],pre_b[N];int main(){ int n,i,k; scanf("%d%d%s",&n,&k,s); pre_a[0]=pre_b[0]=0; for(i=1;i<=n;++i){ if(!(s[i-1]-'a')){ pre_a[i]=pre_a[i-1]+1; pre_b[i]=pre_b[i-1]; }else{ pre_a[i]=pre_a[i-1]; pre_b[i]=pre_b[i-1]+1; } } int low,high,mid,ans=0; for(i=0;i<=n;++i){ low=i,high=n; while(low<=high){ mid=(low+high)>>1; if(pre_a[mid]-pre_a[i]>k && pre_b[mid]-pre_b[i]>k)high=mid-1; else low=mid+1; } ans=Max(ans,high-i); } printf("%d\n",ans);}
D Theseus and labyrinth
题意:给出一个n*m的地图,每个格子代表一个房间,规定房间上哪几个方向有门,之后要想走到相邻房间,该房间必须也要有通向当前房间的门,也可以将地图上各个房间顺时针旋转90度。
/************************************************************************* File Name: cf_D.cpp ID: obsoles1 PROG: LANG: C++ Mail: 384099319@qq.com Created Time: 二 5/31 21:56:49 2016 ************************************************************************/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<map>#include<queue>#include<stack>#include<cmath>#include<cctype>#include<ctime>#include<cstdlib>#include<string>#include<vector>#include<set>#include<bitset>#define Max(x,y) ((x)>(y)?(x):(y))#define Min(x,y) ((x)<(y)?(x):(y))#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))#define ll long long#define Mem0(x) memset(x,0,sizeof(x))#define Mem1(x) memset(x,-1,sizeof(x))#define MemX(x) memset(x,0x3f,sizeof(x))#define pb push_backusing namespace std;const int N=1010;char mp[4][N][N];struct node{ int step,x,y,k;}s,t;queue<node> q;bool vis[4][N][N];int n,m,sx,sy,ex,ey,mx[]={0,0,1,-1},my[]={1,-1,0,0};char change(char x){ if(x=='-')return '|'; if(x=='|')return '-'; if(x=='^')return '>'; if(x=='>')return 'v'; if(x=='v')return '<'; if(x=='<')return '^'; if(x=='L')return 'U'; if(x=='U')return 'R'; if(x=='R')return 'D'; if(x=='D')return 'L'; return x;}bool left(char x){ if(x=='-' || x=='>' || x=='L' || x=='U' || x=='D' || x=='+')return 1; return 0;}bool right(char x){ if(x=='-' || x=='<' || x=='R' || x=='U' || x=='D' || x=='+')return 1; return 0;}bool up(char x){ if(x=='|' || x=='v' || x=='L' || x=='R' || x=='U' || x=='+')return 1; return 0;}bool down(char x){ if(x=='|' || x=='^' || x=='L' || x=='R' || x=='D' || x=='+')return 1; return 0;}bool deal(node s,node t){ char sw=mp[s.k][s.x][s.y],tw=mp[t.k][t.x][t.y]; //cout<<"sw="<<sw<<" tw="<<tw<<endl; if(sw=='+'){ if(s.x-1==t.x)return up(tw); if(s.x+1==t.x)return down(tw); if(s.y-1==t.y)return left(tw); if(s.y+1==t.y)return right(tw); }else if(sw=='-'){ if(s.y-1==t.y)return left(tw); if(s.y+1==t.y)return right(tw); }else if(sw=='|'){ if(s.x-1==t.x)return up(tw); if(s.x+1==t.x)return down(tw); }else if(sw=='^' && s.x-1==t.x) return up(tw); else if(sw=='v' && s.x+1==t.x) return down(tw); else if(sw=='>' && s.y+1==t.y) return right(tw); else if(sw=='<' && s.y-1==t.y) return left(tw); else if(sw=='L'){ if(s.x-1==t.x)return up(tw); if(s.x+1==t.x)return down(tw); if(s.y+1==t.y)return right(tw); }else if(sw=='R'){ if(s.x-1==t.x)return up(tw); if(s.x+1==t.x)return down(tw); if(s.y-1==t.y)return left(tw); }else if(sw=='U'){ if(s.x+1==t.x)return down(tw); if(s.y-1==t.y)return left(tw); if(s.y+1==t.y)return right(tw); }else if(sw=='D'){ if(s.x-1==t.x)return up(tw); if(s.y-1==t.y)return left(tw); if(s.y+1==t.y)return right(tw); } return 0;}void bfs(){ Mem0(vis); while(!q.empty())q.pop(); s.x=sx,s.y=sy,s.step=0,s.k=0; vis[0][sx][sy]=1; q.push(s); while(!q.empty()){ s=q.front(); //cout<<"s("<<s.x<<','<<s.y<<") step="<<s.step<<" k="<<s.k<<endl; q.pop(); if(s.x==ex && s.y==ey){ printf("%d\n",s.step); return; } for(int i=0;i<4;++i){ t=s; t.x+=mx[i],t.y+=my[i]; t.step++; if(t.x<0 || t.x>=n || t.y<0 || t.y>=m || vis[t.k][t.x][t.y] || mp[t.k][t.x][t.y]=='*')continue; if(deal(s,t)){ q.push(t); vis[t.k][t.x][t.y]=1; } } t=s; t.k=(t.k+1)%4; t.step++; if(vis[t.k][t.x][t.y])continue; vis[t.k][t.x][t.y]=1; q.push(t); } puts("-1");}int main(){ int i,j,k; scanf("%d%d",&n,&m); for(i=0;i<n;++i){ scanf("%s",mp[0][i]); for(k=1;k<4;++k){ for(j=0;j<m;++j) mp[k][i][j]=change(mp[k-1][i][j]); } } scanf("%d%d%d%d",&sx,&sy,&ex,&ey); sx--,sy--,ex--,ey--; bfs();}
E The Last Fight Between Human and AI
1 0
- Codeforces Round #354 (Div. 2)
- Codeforces Round #354 (Div. 2)
- Codeforces Round #354 (Div. 2)
- Codeforces Round #354 (Div. 2)
- Codeforces Round #354 (Div 2)
- Codeforces Round #354 (Div. 2) D
- Codeforces Round #354 (Div. 2) A
- Codeforces Round #354 (Div. 2) B
- codeforces Round #354 (Div. 2) A
- Codeforces Round #354 (Div. 2) ABC
- 【解题报告】Codeforces Round #354 (Div. 2)
- Codeforces Round #354 (Div. 2) C
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Docker-Swarm重调度策略
- 【Unity】安卓/ios应用名本地化
- 相机标定
- 打包生成静态库.a文件
- 通过 Navigation View 创建导航抽屉
- Codeforces Round #354 (Div. 2)
- 设计模式 —— 状态模式(State Pattern)
- 为什么Nginx的性能要比Apache高很多?
- A004-补码-(ques=1)
- Chromium网页CPU光栅化原理分析
- 使用MYSQL实现Oracle的Start with...Connect By递归树查询
- CSS布局模型
- Google官方详解 Activity【项目实例不容错过!】
- 乌克兰老油条的钓鱼站 [Steam DotA2]