团战可以输、提莫必须死
Time Limit: 1000MSMemory Limit: 65536KB
ProblemDescription
为了一些你们不知道的原因,我们把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: xy".
ExampleInput
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
ExampleOutput
Teemo: 3 3
BOOM
Hint
Author
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int tu[102][110];
int book[10][10];
int n,m,k;
int jx[] = {-1,1,0,0};
int jy[] ={0,0,-1,1};
struct node
{
int x;
int y;
int ans;
}q[300],t,f;
void bfs(int x,int y,int k)
{ memset(book,0,sizeof(book));
int i;
//int s=0,e=0;
queue<node>g;
t.x = x;
t.y =y;
t.ans = 0;
g.push(t);
book[x][y] = 1;
while(!g.empty())
{
f = g.front();
g.pop();
k--;
if(k==0)
{
printf("Teemo: %d %d\n",f.x,f.y);
return ;
}
int top = 0,temp[5]={0},temp2[5]={0};
for(i =0;i<4;++i)
{
t.x = f.x+jx[i];
t.y = f.y+jy[i];
if(t.x>0&&t.x<=n&&t.y>0&&t.y<=m)
{
top++;
temp[top] = tu[t.x][t.y];
temp2[top] = i;
}
}
if(top==0)
{
printf("BOOM\n");
return ;
}
else if(top==1)
i = temp2[1];
else
{
for(int aa=1;aa<=top;aa++)
{
for(int bb=1;bb<=top-aa;bb++)
{
if(temp[bb]<temp[bb+1])
{
swap(temp[bb],temp[bb+1]);
swap(temp2[bb],temp2[bb+1]);
}
else if(temp[bb]==temp[bb+1]&&temp2[bb]>temp2[bb+1])
{
swap(temp[bb],temp[bb+1]);
swap(temp2[bb],temp2[bb+1]);
}
}
}
i = temp2[1];
}
t.x = f.x+jx[i];
t.y = f.y+jy[i];
if(book[t.x][t.y]==1)
{
printf("BOOM\n");
return ;
}
if(t.x>0&&t.x<=n&&t.y>0&&t.y<=m)
{
t.ans = f.ans+1;
g.push(t);
book[t.x][t.y] = 1;
}
}
//printf("-1\n");
return ;
}
int main()
{
while(~scanf("%d%d%d",&n,&m,&k))
{
//memset(tu,0,sizeof(tu));
memset(book,0,sizeof(book));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&tu[i][j]);
}
}
int x,y;
scanf("%d%d",&x,&y);
bfs(x,y,k);
}
return 0;
}
/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 132ms
Take Memory: 208KB
Submit time: 2017-02-16 10:03:51
****************************************************/