UVa 784 Maze Exploration(DFS)
2013-04-20 21:48
399 查看
这道题比较难办的是输入,有空格,要用gets();然后就是本小妞有马虎了,多写了一个else,结果半天没有音讯!还有就是,使得这个点不超范围,范围是要用&&来判断的,今天耍小聪明||了一下果断错了!
然后‘-’和‘_',减号和下划线今天还打混了!!!这些都要注意了
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 100;
int T, sx, sy;
int a[] = { 0, 0, 1, -1 };
int b[] = { 1, -1, 0, 0 };
int cnt = 0, end = 0;
char g
;
void dfs( int x, int y ) {
g[x][y] = '#';
for ( int i = 0; i < 4; ++i ) {
int xx = x + a[i], yy = y + b[i];
if ( ( xx >= 0 && xx < cnt - 1 ) && ( y >= 0 && y < strlen(g[xx]) ) && ( g[xx][yy] == ' ' || g[xx][yy] == '_' ) ) dfs ( xx, yy );
}
}
int main()
{
scanf("%d", &T);
getchar();
while ( T-- ) {
memset( g, '\0', sizeof(g));
cnt = end = 0;
while ( gets( g[cnt] ) ) {
end = 1;
for ( int i = 0; i < strlen(g[cnt]); ++i ) {
if ( g[cnt][i] != '_' ) end = 0;
if ( g[cnt][i] == '*' ) {
sx = cnt, sy = i;
}
}
cnt++;
if ( end == 1 ) break;
}
dfs( sx, sy );
for ( int i = 0; i < cnt; ++i ) printf("%s\n", g[i]);
}
}
然后‘-’和‘_',减号和下划线今天还打混了!!!这些都要注意了
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 100;
int T, sx, sy;
int a[] = { 0, 0, 1, -1 };
int b[] = { 1, -1, 0, 0 };
int cnt = 0, end = 0;
char g
;
void dfs( int x, int y ) {
g[x][y] = '#';
for ( int i = 0; i < 4; ++i ) {
int xx = x + a[i], yy = y + b[i];
if ( ( xx >= 0 && xx < cnt - 1 ) && ( y >= 0 && y < strlen(g[xx]) ) && ( g[xx][yy] == ' ' || g[xx][yy] == '_' ) ) dfs ( xx, yy );
}
}
int main()
{
scanf("%d", &T);
getchar();
while ( T-- ) {
memset( g, '\0', sizeof(g));
cnt = end = 0;
while ( gets( g[cnt] ) ) {
end = 1;
for ( int i = 0; i < strlen(g[cnt]); ++i ) {
if ( g[cnt][i] != '_' ) end = 0;
if ( g[cnt][i] == '*' ) {
sx = cnt, sy = i;
}
}
cnt++;
if ( end == 1 ) break;
}
dfs( sx, sy );
for ( int i = 0; i < cnt; ++i ) printf("%s\n", g[i]);
}
}
相关文章推荐
- Maze Exploration UVA - 784 (DFS)
- uva 784(dfs)
- uva 784 Maze Exploration(简单dfs)
- uva 784 Maze Exploration 染色 搜索水题 DFS
- uva 784 Maze Exploration 染色 搜索水题 DFS
- UVA - 784 Maze Exploration (简单dfs)
- UVa 784 - Maze Exploration//DFS
- UVA 784 - Maze Exploration(简单DFS)
- uva 784 Maze Exploration(简单dfs)
- uva 784(dfs)
- UVA784--dfs
- uva 784 Maze Exploration(DFS遍历图)
- UVA 784(dfs填充房间)
- uva 784 Maze Exploration(迷宫探索) —— DFS
- UVA 784-Maze Exploration(dfs)
- UVA784_Maze Exploration(DFS)
- UVa784 Maze Exploration(DFS)
- UVA 784 Maze Exploration (DFS || 种子填充)
- 经典第六章 例题 6-12 UVA 572 Oil Deposits(用DFS求连通块)
- UVA 657 The die is cast (DFS*2)