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 FlyingJack at 2018-07-30 20:51:57 on Problem 2488
In Reply To:求助,测的题里给的数据都对,为什么WA了? Posted by:ChineseTea at 2018-07-21 23:35:08
> #include<stdio.h>
> #include<string.h>
> int a[8][2]={{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}};
> int p,q;
> bool judge[27][27];
> int fx[27],fy[27];
> bool dfs(int x,int y,int num);
> int main()
> { 
> 	int n,k,m;
> 	while(scanf("%d",&n) != EOF)
> 	{
> 		for(m=1;m<=n;m++)
> 		{
> 			memset(judge,false,sizeof(judge));
> 			judge[1][1]=true;
> 			scanf("%d%d",&p,&q);
> 			printf("Scenario #%d:\n",n);
> 			if(dfs(1,1,1))
> 			{
> 				for(k=1;k<=p*q;k++)
> 				printf("%c%d",fy[k],fx[k]);
> 			}
> 			else
> 			printf("impossible");
> 			printf("\n\n");
> 		}
> 	}
> }
> bool dfs(int x,int y,int num)
> {
> 	fx[num]=x;fy[num]=y+'A'-1;
> 	int i,nx,ny;
> 	if(num==p*q)
> 	return true;
> 	for(i=0;i<8;i++)
> 	{
> 		nx=x+a[i][0];
> 		ny=y+a[i][1];
> 		if(nx<=p&&nx>=1&&ny<=q&&ny>=1&&!judge[nx][ny])
> 		{
> 			judge[nx][ny]=true;
> 			if(dfs(nx,ny,num+1))
> 			return true;
> 			else
> 			judge[nx][ny]=false;
> 		}
> 	}
> 	return false;
> }

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