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 |
Re:求助,测的题里给的数据都对,为什么WA了?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator