hdu1035 DFS模拟
来源:互联网 发布:西南政法大学网络教育 编辑:程序博客网 时间:2024/06/06 09:08
做水题找感觉,一次AC水过的
#include <iostream>#include <cstdio>using namespace std;int row,column,start;int map[11][11];char dir[11][11];int step;bool flag;int before;void DFS(int x,int y){if(map[x][y] != 0){flag = true;before = map[x][y];return;}step++;map[x][y] = step;int xx,yy;xx = x;yy = y;if(dir[x][y] == 'W'){yy = y - 1;}else if(dir[x][y] == 'E'){yy = y + 1;}else if(dir[x][y] == 'N'){xx = x - 1;}else if(dir[x][y] == 'S'){xx = x + 1;}else{cout<<"error"<<endl;}if(xx >= 0 && xx <= row -1 && yy >= 0 && yy <= column - 1){DFS(xx,yy);}return;}int main(){while(cin>>row>>column){if(row == 0 || column == 0){break;}cin>>start;for(int i = 0; i < row; i++){for(int j = 0; j < column; j++){cin>>dir[i][j];map[i][j] = 0;}}step = 0;flag = false;DFS(0,start-1);if(flag == false){cout<<step<<" step(s) to exit"<<endl;}else{cout<<before-1<<" step(s) before a loop of "<<step-before+1<<" step(s)"<<endl; }}return 0;}
- hdu1035 DFS模拟
- HDU1035 四方向dfs
- hdu1035 Robot Motion (DFS)
- hdu1035 Robot Motion 模拟
- HDU1035 - Robot Motion (模拟)
- HDU1035 Robot Motion(模拟)
- hdu1035
- hdu1035
- hdu1035
- hdu1035
- hdu1035
- hdu1035
- hdu1035
- poj1573&&hdu1035 Robot Motion(模拟)
- hdu1035-模拟问题 机器人走迷宫
- HDU1035深搜
- 10609 - Fractal (模拟,dfs)
- poj1033 模拟(dfs)
- 《HTTP权威指南》---http访问描述
- 通过sharedUserId提高权限
- maxleng的专栏 Android核心分析
- Android 系统属性
- VC控件DateTimePicker使用方法
- hdu1035 DFS模拟
- 分析网站数据要综合进行
- HOWTO: Unpack, Edit, and Re-Pack Boot Images
- xcode 编译 带boost库程序的 一类错误及其解决方式
- Android如何监听开机广播和关机广播
- IP存储技术【转载内容】
- 我的php学习笔记(十八)php的面向对象开发(五)
- C++函数参数传递:按值传递和按引用传递
- C#中静态变量(static)