Codeforces Round #301 C (Div. 2) 【dfs】
2015-06-05 18:10
302 查看
题目链接:http://codeforces.com/contest/540/problem/C
(最近 unhappy!)
题意:初始时候在一个破碎的冰块上,每次只能走到临近的四个未破碎冰块上。未破碎的冰块被踩后变为破碎。且不能在冰块上停留。踩上破碎的冰块就会掉入此坐标。问 是否可以在掉进给定的坐标。
代码:
(最近 unhappy!)
题意:初始时候在一个破碎的冰块上,每次只能走到临近的四个未破碎冰块上。未破碎的冰块被踩后变为破碎。且不能在冰块上停留。踩上破碎的冰块就会掉入此坐标。问 是否可以在掉进给定的坐标。
代码:
[code]#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; }
相关文章推荐
- BaseExpandableListAdapter的用法
- Android Studio打包.so文件教程
- Linux下启动mysql
- How to install the latest Nvidia drivers on Ubuntu 14.04 Trusty Tahr
- [每日一记]php访问mysql
- 《自己动手写框架6》:量身定制规则引擎,适应多变业务场景
- 在windows上通过ssh远程链接linux服务器[转]
- laravel Blade 模板引擎 命令
- 坚持做一件事从现在开始
- Android IOC框架
- 第十三周项目二--形状类族中的虚函数
- 读stalendp文章的笔记之【Shader实例分析(一)-Wave】
- 编译基本类型错误,要加prefix文件
- CODEFORCES 550 C. Divisibility by Eight
- Android基础系列-----------Intent简析
- 测试博文2
- Array类型-操作方法
- Git学习笔记(二)
- 第一个博客 我试试就是是
- 多个相同名称进程的情况下 python脚本监控某个进程