| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求解释 为什么去掉一个=就 AC#include<iostream>
#include<cmath>
using namespace std;
int map[1001][1001];
int d[2][1001][1001];
int dir[4][2]={-1,0,1,0,0,-1,0,1};
int que[500001][2];
int w,h;
int bot,top;
int num;
bool check(int x,int y){
if(x<0||x>=h||y<0||y>=w)
return false;
else
return true;
}
void push(int x,int y){
que[top][0]=x;
que[top++][1]=y;
}
void bfs(int x,int y,int k){
int count,xx,yy,i,j;
count=0;
d[k][x][y]=1;
memset(que,0,sizeof(que));
top=bot=0;
push(x,y);
while(bot<=top){
x=que[bot][0];
y=que[bot++][1];
for(i=0;i<4;i++){
xx=x+dir[i][0];
yy=y+dir[i][1];
if(check(xx,yy)&&d[k][xx][yy]==0&&map[xx][yy]!=1){
d[k][xx][yy]=d[k][x][y]+1;
if(map[xx][yy]==4)
count++;
if(count==num)
return ;
push(xx,yy);
}
}
}
}
int main(){
int i,j;
int px,py,qx,qy;
num=0;
scanf("%d %d",&w,&h);
for(i=0;i<h;i++){
for(j=0;j<w;j++){
scanf("%d",&map[i][j]);
d[0][i][j]=d[1][i][j]=0;
if(map[i][j]==2){
px=i;
py=j;
}
if(map[i][j]==3){
qx=i;
qy=j;
}
if(map[i][j]==4)
num++;
}
}
map[qx][qy]=1;
bfs(px,py,0);
bfs(qx,qy,1);
int sum=w*h;
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(map[i][j]==4&&d[0][i][j]>0&&d[1][i][j]>0){
sum=min(sum,d[0][i][j]+d[1][i][j]-2);
}
}
}
printf("%d\n",sum);
system("pause");
return 0;
}
这是WA 可是bot<top就AC了。。。。。不知道为什么 求解释
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator