记录编号 |
30546 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[BYVoid S1] 血色叛徒 |
最终得分 |
100 |
用户昵称 |
Truth.Cirno |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.327 s |
提交时间 |
2011-10-30 11:24:19 |
内存使用 |
5.27 MiB |
显示代码纯文本
#include <cstdio>
using namespace std;
int quex[250000],quey[250000],masx[250000],masy[250000],tim[501][501]={{0}};
bool master[501][501]={{false}};
/* Sources' positions are saved in array quex[] and quey[] . */
/* We also use array quex[] and quey[] to expand new illness sources . */
/* Masters' positions are saved in array masx[] and masy[] ans master[][] . */
/* For conveniece , in array tim[][] which saves the time when people get illness , we use 1 as 0 , use 2 as 1 , etc . Then we use 0 to judg whether it is s source , whether it has got the illness . */
int main(void)
{
freopen("crusade.in","r",stdin);
freopen("crusade.out","w",stdout);
const int RUL[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int i,Ln,Co,sounum,masnum,masrest,tempx,tempy,head,tail=0;
scanf("%d %d %d %d",&Ln,&Co,&sounum,&masnum);
masrest=masnum;
head=sounum-1;
for (i=0;i<sounum;i++)
{
scanf("%d %d",&quex[i],&quey[i]);
tim[quex[i]][quey[i]]=1;
}
for (i=0;i<masnum;i++)
{
scanf("%d %d",&masx[i],&masy[i]);
master[masx[i]][masy[i]]=true;
if (tim[masx[i]][masy[i]])
masrest--;
}
while (masrest)
{
for (i=0;i<4;i++)
{
tempx=RUL[i][0]+quex[tail];
tempy=RUL[i][1]+quey[tail];
if (tim[tempx][tempy]==0&&tempx>=1&&tempx<=Ln&&tempy>=1&&tempy<=Co)
{
head++;
quex[head]=tempx;
quey[head]=tempy;
tim[tempx][tempy]=1+tim[quex[tail]][quey[tail]];
if (master[tempx][tempy])
masrest--;
}
}
tail++;
}
for (i=0;i<masnum;i++)
printf("%d\n",tim[masx[i]][masy[i]]-1);
fclose(stdin);
fclose(stdout);
return(0);
}