0_0_9224019_30522\Main.java:1: 非法字符: \35
#include <stdio.h>int map[1001][1001];int b[4][2]={{-1,0},{0,1},{1,0},{0,-1}};int x1,x2,y1,y2;int n,m;int visited[1001][1001];typedef struct{ int x; int y; int count;}node;node pass[1000000];int bfs(){ int i; int front; int rear; node a; a.count=0; front=0; pass[0].x=x1; pass[0].y=y1; pass[0].count=0; visited[x1][y1]=1; rear=1; while(front!=rear) { if(pass[front].count>=3) return 0; for(i=0;i<4;i++) { a.x=pass[front].x+b[i][0]; a.y=pass[front].y+b[i][1]; //printf("a.x%d a.y%d map[a.x][a.y]%d\n\n",a.x,a.y,map[a.x][a.y]); while(a.x>=1&&a.x<=n&&a.y>=1&&a.y<=m&&map[a.x][a.y]==0) { if(visited[a.x][a.y]==0) { a.count=pass[front].count+1; pass[rear]=a; rear++; visited[a.x][a.y]=1; if(a.x==x2&&a.y==y2) if(a.count<=3) return 1; else return 0; } a.x+=b[i][0];// 访问过的点,不进入队列中,但仍可沿此方向访问,且此方向都是不转折的,其余均是转折 a.y+=b[i][1]; } } front++; } return 0;}int main(){ int i,j; int p; int t; while(scanf("%d%d",&n,&m)!=EOF) { if(n+m==0) break; for(i=1;i<=n;i++) for(j=1;j<=m;j++) scanf("%d",&map[i][j]); scanf("%d",&p); while(p--) { for(i=1;i<1001;i++) for(j=1;j<1001;j++) visited[i][j]=0; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); if(map[x1][y1]!=map[x2][y2]||map[x1][y1]==0) { printf("NO\n"); continue; } else { t=map[x2][y2]; map[x2][y2]=0; if(bfs()) printf("YES\n"); else printf("NO\n"); } map[x2][y2]=t; } } return 0; }
|