标签:blog class code color get int
题目地址:http://acm.fzu.edu.cn/problem.php?pid=1920
题目大意是给定一个n*n的图,模拟扫雷游戏,0代表没有雷区,1代表附近九宫格内只有一个雷……
如果不懂的话去玩下扫雷,挺好玩的,99个雷的玩了好几百盘才赢了一次。。。。。。。。。。。。
此题假设神操作,点不到雷,问你最少要多少下才可以把图中非雷的点完,怎么样才最快呢?
当然先点0啦,,,,,,,,
好吧,不废话了。。。。。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 |
#include <stdio.h>#include <stdlib.h>#include <string.h>int dir[8][2]={{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0}};char
map[10][10];int n;void
dfs(int
x,int y){ int
xx; int
yy; map[x][y]=‘#‘; for(int
i=0;i<8;i++) { xx=x+dir[i][0]; yy=y+dir[i][1]; if(xx<0||xx>=n||yy<0||yy>=n) { continue; } //printf("%d%d^^",xx,yy); if(map[xx][yy]==‘0‘) { dfs(xx,yy); } if(map[xx][yy]!=‘#‘&&map[xx][yy]!=‘@‘) { map[xx][yy]=‘#‘; } }}int
main(){ int
i,j,k,t,s; scanf("%d",&t); for(s=0;s<t;s++) { int
count=0; scanf("%d",&n); getchar(); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%c",&map[i][j]); } getchar(); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(map[i][j]==‘0‘) { dfs(i,j); count++; } } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(map[i][j]!=‘#‘&&map[i][j]!=‘@‘) { count++; } } } printf("Case %d: %d\n",s+1,count); } return
0;} |
fzu 1920 Left Mouse Button(简单深搜题),布布扣,bubuko.com
fzu 1920 Left Mouse Button(简单深搜题)
标签:blog class code color get int
原文地址:http://www.cnblogs.com/ccccnzb/p/DFS.html