Codeforces Round #301 C (Div. 2) 【dfs】
来源:互联网 发布:南京行知教育集团 编辑:程序博客网 时间:2024/05/04 07:06
题目链接:http://codeforces.com/contest/540/problem/C
(最近 unhappy!)
题意:初始时候在一个破碎的冰块上,每次只能走到临近的四个未破碎冰块上。未破碎的冰块被踩后变为破碎。且不能在冰块上停留。踩上破碎的冰块就会掉入此坐标。问 是否可以在掉进给定的坐标。
代码:
#include <stdio.h>#include <iostream>#include <math.h>#include <string.h>#include <string>#include <algorithm>#include <ctype.h>#include <time.h>#include <queue>#include <stdlib.h>using namespace std;int n, m, ok;char p[510][510];int sx, sy, ex, ey;int dir[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };int check(int x, int y){ if (x < 1 || x > n || y < 1 || y > m) return 0; if (p[x][y] == 'X') { if (x == ex && y == ey ) ok = 1; return 0; } return 1;}void dfs(int x,int y){ p[x][y] = 'X'; for (int i = 0; i < 4; i++) { int xx = x + dir[i][0]; int yy = y + dir[i][1]; if (check(xx, yy)) dfs(xx, yy); } }int main(){ while (scanf("%d%d", &n, &m) != EOF) { for (int i = 1; i <= n; i++) scanf("%s",p[i]+1); //cout << endl; //for (int i = 1; i <= n; i++) // puts(p[i]+1); scanf("%d%d%d%d",&sx,&sy,&ex,&ey); ok = 0; dfs(sx,sy); if (ok) puts("YES"); else puts("NO"); } return 0;}
0 0
- Codeforces Round #301 C (Div. 2) 【dfs】
- Codeforces Round #359 (Div. 2) C DFS
- Codeforces Round #321 (Div. 2) C DFS
- Codeforces Round #376 (Div. 2)C(DFS)
- Codeforces Round #256 (Div. 2) C. Painting Fence (DFS)
- Codeforces Round #321 (Div. 2)(C)模拟,DFS
- Codeforces Round #359 (Div. 2) C. Robbers' watch (DFS)
- Codeforces Round #360 (Div. 2) C DFS判断二分图
- Codeforces Round #374 (Div. 2) C. Journey(dfs+dp)
- Codeforces Round #376 (Div. 2) C dfs+并查集
- Codeforces Round #398 (Div. 2) -- C. Garland (dfs)
- Codeforces Round #398(Div. 2)C. Garland【Dfs+思维】
- Codeforces Round #245 (Div. 2) C. Xor-tree DFS
- Codeforces Round #308 (Div. 2) C. Vanya and Scales dfs
- Codeforces Round #321 (Div. 2) C. Kefa and Park dfs
- Codeforces Round #398 (Div. 2) C. Garland —— DFS
- Codeforces Round #197 (Div. 2) C(dfs)
- Codeforces Round #428 (Div. 2) C. Journey(dfs deep
- ListView使用注意事项
- golang runtime-gdb.py的问题
- BaseExpandableListAdapter的用法
- E430(c) 修改版BIOS刷入攻略
- 关于缓冲区溢出(Buffer Overflow)
- Codeforces Round #301 C (Div. 2) 【dfs】
- 动态创建二维vector数组
- hdu 3336 Count the string 【kmp + dp】
- Gradle添加so文件
- hdu 2554 N对数的排列问题 【数学】
- 南阳 水仙花数
- Android与IOS异同点对比(1)------ 显示
- poj 2229 Sumsets【DP】
- iOS 工程解耦后 消息传递方式