为了一些你们不知道的原因,我们把LOL的地图抽象为一个n×m的矩阵
提莫积攒了k个蘑菇准备种到地图上去,因为提莫的背篓漏了,所以每一个提莫走过的地方都会被摆下一个蘑菇,两个蘑菇同时种在一个地方的话就会爆炸,所以一旦即将出现这种情况,提莫会直接传送回家,防止自己被炸死
之前的排位赛中因为乱种蘑菇提莫已经被骂了好多次了,所以这次提莫特地查资料对当前地图的各个位置种下蘑菇的价值做了统计,但是因为提莫行动比较笨拙,所以他每次只能移动到上下左右四个方向的格子中(如果该方向有格子的话
每次行走提莫会从四个方向挑选一个权值最大的方向,如果有最大的权值有多个,他会从这多个相同的最大权值之中找出没有走过并且按照上下左右的优先顺序挑选一个合适的方向走。如果最大权值都被走过了,他会心灰意冷的传送回家,此时直接输出"BOOM"
(提莫会顺手在他的起点顺手种一个蘑菇下去
Input
多组输入。
输入第一行包含地图大小n,m,蘑菇数量k。(1 <= n,m <= 100,1 <= k <= n*m)
接下来的n行每行有m个数(并且保证每个数的范围[1,1e5)
接下来两个整数x,y代表提莫的起点
Output
如果走到最后没有地方可以种蘑菇了,但蘑菇还没全部种完,输出"BOOM".
如果蘑菇在半途中种完了,输出提莫所处的坐标"Teemo: x y".
Example Input
3 3 3 1 2 3 4 5 6 7 8 9 2 2 3 3 5 1 2 3 4 5 6 7 8 9 2 2
Example Output
Teemo: 3 3 BOOM
这道题不难,就是感觉要求有点hentai,,就是最后一段那里
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int N = 110;
struct node
{
int x, y, z;
};
int n, m, k;
int map[N][N];
bool vis[N][N];
int sx, sy;
int xx[4] = {-1, 1, 0, 0};
int yy[4] = {0, 0, -1, 1};
void BFS(int si, int sj)
{
queue<node> q;
struct node t, u;
t.x = si;
t.y = sj;
t.z = k-1;
q.push(t);
vis[si][sj] = 1;
while(!q.empty())
{
u = q.front();
q.pop();
if(u.z == 0)
{
printf("Teemo: %d %d\n", u.x, u.y);
return;
}
int i, j, maxn = 0, MAX = 0;
for(int l = 0; l < 4; l++)
{
t.x = u.x + xx[l];
t.y = u.y + yy[l];
if(maxn < map[t.x][t.y] && !vis[t.x][t.y])
{
i = t.x;
j = t.y;
maxn = map[t.x][t.y];
}
MAX = max(MAX, map[t.x][t.y]);
}
if(maxn != MAX)
{
printf("BOOM\n");
return;
}
vis[i][j] = 1;
t.x = i;
t.y = j;
t.z = u.z-1;
q.push(t);
}
}
int main()
{
while(~scanf("%d%d%d", &n, &m, &k))
{
memset(vis, 0, sizeof(vis));
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%d", &map[i][j]);
scanf("%d%d", &sx, &sy);
BFS(sx, sy);
}
return 0;
}