题目链接:https://nanti.jisuanke.com/t/28865
题目描述
Plague Inc. is a famous game, which player develop virus to ruin the world.
JSZKC wants to model this game. Let’s consider the world has N*M cities. The world has N rows and M columns. The city in the X row and the Y column has coordinate (X,Y).
There are K cities which are sources of infection at the 0th day. Each day the infection in any infected city will spread to the near four cities (if exist).
JSZKC wants to know which city is the last one to be infected. If there are more than one cities , answer the one with smallest X firstly, smallest Y secondly.
输入
The input file contains several test cases, each of them as described below.
- The first line of the input contains two integers N and M (1 ≤ N,M ≤ 2000), giving the number of rows and columns of the world.
- The second line of the input contain the integer K (1 ≤K ≤ 10).
- Then K lines follow. Each line contains two integers Xi and Yi, indicating (X i ,Y i ) is a source. It’s guaranteed that the coordinates are all different.
There are no more than 20 test cases.
输出
For each testcase, output one line with coordinate X and Y separated by a space.
样例输入
3 3 1 2 2 3 3 2 1 1 3 3
样例输出
1 1 1 3
来源/分类
题意:就是给你n*m的格子,然后k个点,K个点有火,开始四个方向蔓延,问你最后烧的那个格子的位置,有多个的话,x优先再y优先。
当初去徐州现场赛,stlT到怀疑人生,今天学弟问我这个题,然后我就想了想,然后暴力bfs测试了下,大蒜头竟然过了,然后看了时间大蒜头把时间多了0.5s,然后upc果不其然T了,然后换了一下暴力的方法,k*m*n,然后1s过了,bfs肯定是多次进入然后时间GGGGGG,然后就暴力然后就XJB,然后就ac.
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int Map[2005][2005];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int k,a,b,Max=-1;
scanf("%d",&k);
memset(Map,INF,sizeof(Map));
while(k--)
{
scanf("%d%d",&a,&b);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
Map[i][j]=min(Map[i][j],abs(a-i)+abs(b-j));
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
Max=max(Max,Map[i][j]);
int flag=1;
for(int i=1;i<=n && flag;i++)
{
for(int j=1;j<=m;j++)
{
if(Map[i][j]==Max)
{
printf("%d %d\n",i,j);
flag=0;
break;
}
}
}
}
return 0;
}