Codeforces #325 Div2 D Phillip and Trains(模拟)
来源:互联网 发布:红颜知已的歌词 编辑:程序博客网 时间:2024/05/20 07:19
题目链接:
Codeforces #325 Div2 D Phillip and Trains
题意:
有3个长度为n的隧道,有个人需要从s位置出发走出隧道的右端,有若干个火车在隧道里,
每秒钟人向右移动一格,然后选择向上、向下、待在原地,火车每秒钟向左移动两格。问能否走出隧道?
分析:
模拟。将每秒钟可以走到的位置记录下来,然后更新火车位置,检查结果。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <climits>#include <cmath>#include <ctime>#include <cassert>#include <set>#define IOS ios_base::sync_with_stdio(0); cin.tie(0)using namespace std;const int MAXN=110;int T,n,m;int vis[MAXN][MAXN];char s[5][MAXN];int main(){ scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); memset(vis,0,sizeof(vis)); set<pair<int,int> > ans[2]; for(int i=0;i<3;i++){ scanf("%s",s[i]); for(int j=0;j<n;j++){ if(s[i][j]=='s'){ //起点 ans[0].insert(make_pair(i,j)); continue; } if(isalpha(s[i][j])) vis[i][j]=1; } } int ok=0,pre,cur=0; while(1){ cur^=1; pre=1-cur; //更新hero ans[cur].clear(); for(set<pair<int,int> > :: iterator it=ans[pre].begin();it!=ans[pre].end();it++){ pair<int,int> tmp=(*it); //先检查有没有已经出来了 int x=tmp.first,y=tmp.second+1; if(y>=n){ ok=1; break; } if(vis[x][y]) continue; ans[cur].insert(make_pair(x,y)); if(x-1>=0 && !vis[x-1][y]) { ans[cur].insert(make_pair(x-1,y)); } if(x+1<3 && !vis[x+1][y]) { ans[cur].insert(make_pair(x+1,y)); } } if(ok==1) break; //更新train for(int i=0;i<3;i++){ for(int j=0;j<n;j++){ if(vis[i][j]){ if(j-2>=0) vis[i][j-2]=1; vis[i][j]=0; } } } //去除无效ans set<pair<int,int> > wrong; for(set<pair<int,int> > :: iterator it=ans[cur].begin();it!=ans[cur].end();it++){ pair<int,int> tmp=(*it); int x=tmp.first,y=tmp.second; if(vis[x][y]) { wrong.insert(tmp); } } for(set<pair<int,int> > :: iterator it=wrong.begin();it!=wrong.end();it++){ pair<int,int> tmp=(*it); ans[cur].erase(tmp); } if(ans[cur].size()==0) { ok=0; break; } } if(ok) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- Codeforces #325 Div2 D Phillip and Trains(模拟)
- CodeForces #325 D. Phillip and Trains
- Codeforces #325 D. Phillip and Trains (bfs)
- CF Round #325 Div2 D. Phillip and Trains
- 【Codeforces Round #325 (Div. 2)】D. Phillip and Trains
- Codeforces Round #325 (Div. 2) D. Phillip and Trains
- Codeforces Round #325 (Div. 2)-D. Phillip and Trains
- CodeForces 586D Phillip and Trains (基础搜索 -- DFS)
- CodeForces 586D Phillip and Trains(搜索)
- 【33.33%】【codeforces 586D】Phillip and Trains
- Codeforces 586D Phillip and Trains
- Codeforces 586D Phillip and Trains
- Codeforces 586D Phillip and Trains 题解
- Codeforces Round #325 (Div. 2) D. Phillip and Trains (BFS)
- Codeforces 586D Phillip and Trains【思维+Bfs】好题~!
- Codeforces 586D Phillip and Trains dfs —— Round #325 (Div. 2)
- 简单搜索题(D. Phillip and Trains)
- Codeforces 585B Phillip and Trains(dp)
- 写一个字符串到文件
- [python]gevent的安装
- Tmux 命令总结
- hdu1698
- C语言标准库之<float.h>
- Codeforces #325 Div2 D Phillip and Trains(模拟)
- 重试C语言之C语言变量
- PAT-B 1024. 科学计数法
- java基础 -- 六哥
- 127.0.0.1和localhost和本机IP三者的区别!!!
- Qt实战经验
- 算法的时间复杂度的计算
- [leetcode] 345. Reverse Vowels of a String 解题报告
- Django 文档自翻自用中文版(2.1-2.1.3)