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

Re:唉,醉了,真心找不到哪儿wa了,有没有大神帮帮忙?

Posted by zhouge at 2017-03-06 18:35:46 on Problem 2488
In Reply To:唉,醉了,真心找不到哪儿wa了,有没有大神帮帮忙? Posted by:NWPU_2014302598 at 2015-07-14 23:19:38
> #include<cstdio>
> #include<cstring>
> 
> int h,w,k=0,vis[30],flag[30][30]={0};
> int a[8]={-1,1,-2,2,-2,2,-1,1};
> int b[8]={-2,-2,-1,-1,1,1,2,2};
> 
> using namespace std;
> 
> int dfs(int sx,int sy,int step)
> {
> 
> 	if(step==h*w){
> 		vis[k]=sx*h+sy;
> 		k++;
> 		return 1;
> 	}
> 	for(int i=0;i<8;i++){
> 
> 		int nx=sx+a[i];
> 		int ny=sy+b[i];
> 
> 
> 		if(nx<0||nx>=h||ny<0||ny>=w||flag[nx][ny])continue;
> 
> 		
> 
> 		flag[nx][ny]=1;
> 		if(dfs(nx,ny,step+1)){
> 			vis[k]=sx*h+sy;
> 			k++;
> 			return 1;
> 		}
> 		flag[nx][ny]=0;
> 	}
> 	return 0;
> }
> 
> 
> int main()
> {
>     //freopen("out.txt","w",stdout);
> 	int N;
> 	scanf("%d",&N);
> 	for(int j=1;j<=N;j++){
> 
> 		memset(flag,0,sizeof(flag));
> 
> 		scanf("%d %d",&h,&w);
> 		printf("Scenario #%d:\n",j);
> 
> 		flag[0][0]=1;
> 		k=0;
> 
> 		if(!dfs(0,0,1))printf("impossible");
> 		else for(int i=k-1;i>=0;i--){
> 			char c=vis[i]%h+'A';
> 			printf("%c%d",c,vis[i]/h+1);
> 		}
> 		putchar('\n');
> 		if(j!=N)putchar('\n');
> 
> 	}
> 	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