UVa784 Maze Exploration
// 题意:输入一个迷宫,从*开始遍历,把可达点标记为字符#
注意迷宫边界不规则,要用strlen判断。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int maxn = 100 + 5;
char maze[maxn][maxn]; int dr[]={0, 0, -1, 1};
int dc[]={1, -1, 0, 0}; int R; void dfs(int r, int c)
{
if(r<0 || r>=R || c<0 || c >=strlen(maze[r])) return;
if(maze[r][c] == 'X' || maze[r][c] == '#') return;
maze[r][c]='#';
for(int i=0;i<4;i++)
{
int nr=r+dr[i];
int nc=c+dc[i];
dfs(nr, nc);
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("./uva784.in", "r", stdin);
#endif
int T;
scanf("%d", &T); gets(maze[0]);
while(T--) {
R=0;
while(1) {
gets(maze[R]);
if(maze[R][0]=='_')
break;
R++;
}
int j=0;
while(j<R)
{
char *p;
if((p=strchr(maze[j], '*'))!=0)
{
int r, c;
c=p-maze[j];
r=j;
dfs(r, c);
}
j++;
} j=0;
while(j<=R)
printf("%s\n", maze[j++]); } return 0;
}
UVa784 Maze Exploration的更多相关文章
- [UVA] 784 - Maze Exploration
Maze Exploration A maze of rectangular rooms is represented on a two dimensional grid as illustra ...
- uva 784 Maze Exploration 染色 搜索水题 DFS
染色问题,其实就是看看图上某一点能扩散多少. 用DFS解决,因为BFS不是很熟 =-=...以后要多练. 提交后32ms,优化了一下,在递归前进行判定,优化到22ms,不是优化的很好... 代码: # ...
- 784 - Maze Exploration
#include <stdio.h> #include <string.h> char maze[50][100]; void search(int i,int j) { if ...
- uva 784 Maze Exploration(简单dfs)
这道题看上去非常麻烦,什么迷宫啊.门之类的,事实上挺简单的,就是让把与 * 连通的都置为 # 包含 * , 直接dfs就能够了,只是我wa了好多次...最后居然是多读了一个换行.忘了加getchar( ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Undirected Graphs
无向图 Introduction 图是由边连接的点的集合,有着广泛的应用空间. 一些图的术语,点,边,路径,环(圈),连通分量(子图). 简单路径不重复经过点,简单环不含有重复点和边,简单图不含自环和 ...
- Backtracking algorithm: rat in maze
Sept. 10, 2015 Study again the back tracking algorithm using recursive solution, rat in maze, a clas ...
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
- (期望)A Dangerous Maze(Light OJ 1027)
http://www.lightoj.com/volume_showproblem.php?problem=1027 You are in a maze; seeing n doors in fron ...
随机推荐
- 推荐 15 个 Angular.js 应用扩展指令(参考应用)
几天前我们看到Angular 1.4.0发布了-一个以社团为驱动的发布版本涵盖了400多个GitHub的提交,增加了对特性的提升,比如动画,以及可用性. 官方新闻发布稿 覆盖了绝大部分,这同样值得放于 ...
- NavieBayes中的多项式与伯努力模型
1文本分类过程 例如文档:Good good study Day day up可以用一个文本特征向量来表示,x=(Good, good, study, Day, day , up).在文本分类中,假设 ...
- Mybatis学习——一对多关联表查询
1.实体类 public class Student { private int id; private String name; } public class Classes { private i ...
- iOS - 操作文件目录的方法
转:http://blog.csdn.net/marujunyy/article/details/11579183 使用目录的常用方法: //获取当前目录 - (NSString *)currentD ...
- DevExpress GridView属性设置 z
本文主要总结控件的属性设置,附上图片,给大家一个参考.后续会给大家分享功能实现和使用的小技巧. GirdControl是数据的容器,它包含多种显示方式,GridView则是一种二维表格视图. 绑定数据 ...
- CCMoveTo 等函数理解
CCMoveTo: 使用CCMoveTo action来让对象从右侧屏幕外移动到屏幕左侧.注意可以通过指定duration参数控制这一过程需要多久,这里我们随机给他2-4秒的时间. CCCallFun ...
- Oracle归档方式设置
一 设置为归档方式Sql代码 sql> archive log list; #查看是不是归档方式 sql> alter system set log_archive_start=true ...
- PHP 实现下载文件的方法
方法一: header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); ...
- 树-哈夫曼树(Huffman Tree)
概述 哈夫曼树:树的带权路径长度达到最小. 构造规则 1. 将w1.w2.-,wn看成是有n 棵树的森林(每棵树仅有一个结点): 2. 在森林中选出根结点的权值最小的两棵树进行合并,作为一棵新树的左. ...
- HTML 5:绘制旋转的太极图
HTML: <!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title& ...