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 ...
随机推荐
- json转csv
import re # csv格式 # 'k1,k2,k3\nv1,v2,v3\nv4,v5,v6\n' market_list_data = { "data": [ { &quo ...
- css垂直水平居中方案
1. 水平居中 如果是inline元素:在父元素上面设置text-align:center; 如果是block元素:设置宽度和margin:0 auto; 如果是多块级元素:在父元素上面设置text- ...
- 快速搭建建SSH服务
一般来说如果用Ubuntu作为服务器,我们经常需要通过其他客户端远程连接它. 远程连接需要使用SSH,这里列出了一个快速完成这一任务的方法. 键入命令 # sudo apt-get install o ...
- jQuery点击div其他地方隐藏div
$(document).bind("click",function(e){ var target = $(e.target); ){ $("#regionlist&quo ...
- 定义页面的Dispose方法:[before]unload事件启示录
前言 最近实施的同事报障,说用户审批流程后直接关闭浏览器,操作十余次后系统就报用户会话数超过上限,咨询4A同事后得知登陆后需要显式调用登出API才能清理4A端,否则必然会超出会话上限. 即使在页面上增 ...
- HDU 5432 Pyramid Split
题意:有n个底面是正方形的四棱锥,用一个水平截面将所有四棱锥分成两半,要求上一半体积的和等于下一半,求水平截面的高度,输出整数部分. 解法:二分截面高度.比赛的时候二分写不明白了orz…… 代码: # ...
- java web 学习五(servlet开发1)
一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...
- linux命令——scp 两台linux机器间文件或目录传输
不同的Linux之间copy文件常用有3种方法: 第一种:ftp,也就是其中一台Linux安装ftpServer,这样可以另外一台使用ftp的client程序来进行文件的copy. 第二种:采用sam ...
- 《Python 学习手册4th》 第十章 Python语句简介
''' 时间: 9月5日 - 9月30日 要求: 1. 书本内容总结归纳,整理在博客园笔记上传 2. 完成所有课后习题 注:“#” 后加的是备注内容 (每天看42页内容,可以保证月底看完此书) “重点 ...
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
UVa11995 I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...