cf 540 C Ice Cave
来源:互联网 发布:google浏览器 for mac 编辑:程序博客网 时间:2024/05/01 10:26
当终点为 “ X ” 时,只要起点能到达终点就输出 " YES " 。
当终点为 " . " 时,输出" YES " 的条件为 1:到达 。
2:终点边上四个方块中除了包含在到达终点的路径上
的那块,至少还有一块是可走的 " . " 或者是起点。
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string.h>using namespace std;int a[505][505];int b[505][505];int n,m;int fx,fy;int s1,s2,e1,e2;int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};int dfs(int x,int y){ a[x][y]=1; for(int i=0;i<4;i++){ int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(xx==e1&&yy==e2){fx=x;fy=y;return 1;} if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&a[xx][yy]==0){ //a[x][y]=1; if(dfs(xx,yy))return 1; } } return 0;}int main(){ while(scanf("%d%d",&n,&m)!=EOF){ memset(a,0,sizeof(a)); char tmp; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>tmp; a[i][j]=tmp=='.'?0:1; b[i][j]=a[i][j]; } } scanf("%d%d%d%d",&s1,&s2,&e1,&e2); if(b[e1][e2]==1){ if( dfs(s1,s2) )puts("YES"); else puts("NO"); } else{ if( dfs(s1,s2) ){ int num=0; for(int i=0;i<4;i++){ int xx=e1+dir[i][0]; int yy=e2+dir[i][1]; if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&b[xx][yy]==0&& (xx!=fx||yy!=fy ) )num++; if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&xx==s1&&yy==s2&& (xx!=fx||yy!=fy ) )num++; } if( num>=1)puts("YES"); else puts("NO"); } else puts("NO"); } } return 0;}
0 0
- cf 540 C Ice Cave
- cf 540-C. Ice Cave
- cf#301-C. Ice Cave-BFS
- Ice Cave-CF-C(bfs)
- CF Ice Cave
- CodeForces 540C Ice Cave
- CF #301 504C C. Ice Cave BFS
- C. Ice Cave (CF #301 (Div. 2) 搜索bfs)
- CodeForces 540C Ice Cave (BFS)
- CodeForces 540 C Ice Cave (BFS)
- codeforces 540C Ice Cave【BFS】
- Codeforces 540C Ice Cave (BFS)
- Ice Cave
- #301 (div.2) C. Ice Cave
- 【Codeforces】C. Ice Cave(bfs)
- Codeforces 301(div 2) C. Ice Cave
- Codeforces Round #301 (Div. 2)C - Ice Cave-bfs
- Codeforces Round #301 (Div. 2) C. Ice Cave(BFS)
- jsp中使用s:if比较时间
- 类属性复制实现
- View设置背景渐变色(shape,gradient)
- Java泛型(一) 泛型的概念 基础
- Android仿美团团购详情页下拉图片放大效果,简单可直接用在项目中
- cf 540 C Ice Cave
- 关于delete和deletelater的问题
- Java并发编程:线程池的使用
- Objective-C 12 类别Category
- iOS集成极光推送,绕过一些坑
- Storm+Kafka集成
- UITaableView的section间隔设置
- 死锁-1.0.2
- IOS侧滑,手势向右划问题