Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

同志们,求大神们帮我看看这道题,太难了

Posted by w2006 at 2019-07-27 19:35:57 on Problem 1101
#include<cstdio>
#include<cstring>
const int N=100;
int m,n,x1,x2,y1,y2;//m列 n行
char ch;
int map[N][N];
struct node{
	int x,y;
	int dep,s;
};
struct step{
	int x,y;
};
step d[5]={{0,0},{0,1},{0,-1},{1,0},{-1,0},};
node data[N*N];
bool flag[N][N];
int op,cl;
int num=0;
int main(){
	//freopen("poj1101.in","r",stdin);
	//freopen("poj1101 2.out","w",stdout);
	while(1){
		scanf("%d%d",&m,&n);
		//printf("%d %d ",n,m);
		if(n==0 and m==0) return 0;
		memset(map,0,sizeof map);
		for(int i=1;i<=n;i++){
			getchar();
			for(int j=1;j<=m;j++){
				scanf("%c",&ch);
				if(ch=='X') map[i][j]=1;
				else map[i][j]=0;
			}
		}
		
		++num;
		printf("Board #%d:\n",num);
		int ans=0x7fffffff;
		int num1=0;
		while(1){
			scanf("%d%d%d%d",&y1,&x1,&y2,&x2);
			if(x1==0 and y1==0 and x2==0 and y2==0) {	
				printf("\n");
				break;
			}
			memset(flag,true,sizeof flag);
			op=0;cl=1;
			data[cl].x=x1;
			data[cl].y=y1;
			data[cl].dep=0;
			data[cl].s=-1;
			flag[x1][y1]=false;
			bool f1=false;
			while(op<cl){
				++op;
				int xx=data[op].x;
				int yy=data[op].y;
				int dep=data[op].dep;
				int s=data[op].s;
				for(int i=1;i<=4;i++){
					int xxx=xx+d[i].x;
					int yyy=yy+d[i].y;
					if((flag[xxx][yyy] and !map[xxx][yyy] and xxx>=0 and yyy>=0 and xxx<=n+1 and yyy<=m+1) or xxx==x2 and yyy==y2){
						++cl;
						data[cl].x=xxx;
						data[cl].y=yyy;
						data[cl].s=i;
						if(s!=i) data[cl].dep=dep+1;
						else data[cl].dep=dep;
						flag[xxx][yyy]=false;
						
						if(xxx==x2 and yyy==y2){
							f1=true;
							if(ans>data[cl].dep) ans=data[cl].dep;
							//printf("%d ",ans);
						}
					} 
				} 
			}
			++num1;
			if(f1) printf("Pair %d: %d segments.\n",num1,ans);
			else printf("Pair %d: impossible.\n",num1);
		}
	}
	
	return 0;
	
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator