-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbombBFS.c
More file actions
114 lines (92 loc) · 2.15 KB
/
Copy pathbombBFS.c
File metadata and controls
114 lines (92 loc) · 2.15 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
struct note
{
int x;
int y;
};
char a[20][21];
int getnum(int i, int j)
{
int sum, x, y;
sum = 0;
x=i; y=j;
while(a[x][y] != '#')
{
if(a[x][y] == 'G')
sum++;
x--;
}
x=i; y=j;
while(a[x][y] != '#')
{
if(a[x][y] == 'G')
sum++;
x++;
}
x=i; y=j;
while(a[x][y] != '#')
{
if(a[x][y] == 'G')
sum++;
y--;
}
x=i; y=j;
while(a[x][y] != '#')
{
if(a[x][y] == 'G')
sum++;
y++;
}
return sum;
}
int main()
{
struct note que[401];
int head=1, tail=1;
int book[20][20] = {0};
int i,j,k,sum,max=0,mx,my,n,m,startx,starty,tx,ty;
int next[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
scanf("%d %d %d %d", &n, &m, &startx, &starty);
for(i=0; i<=n-1; i++)
scanf("%s", a[i]);
que[tail].x = startx;
que[tail].y = starty;
tail++;
//千万记得用初始位置进行最大值和状态值的标记
book[startx][starty] = 1;
max = getnum(startx,starty);
mx = startx;
my = starty;
//###
// printf("%d", getnum(5,3));
while(head<tail)
{
for(k=0; k<4; k++)
{
tx = que[head].x + next[k][0];
ty = que[head].y + next[k][1];
if(tx<0 || tx>n-1 || ty<0 || ty>m-1)
continue;
if(a[tx][ty] == '.' && book[tx][ty] == 0)
{
book[tx][ty] = 1;
que[tail].x = tx;
que[tail].y = ty;
tail++;
sum = getnum(tx, ty);
// 为何不能不直接如下这么写???
// if(getnum(tx,ty) > max)
if(sum > max)
{
max = sum;
mx = tx;
my = ty;
}
}
}
head++;
}
printf("Place the bomb in (%d,%d), down %d monsters\n", mx, my, max);
getchar();getchar();
return 0;
}