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 |
写得很烂的代码贴一个……#include <cstdio> #include <cstring> using namespace std; const int around[8][2]={{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}}; int data[27][27],m,n,current; char answer[1352]; bool dfs(int x,int y) { data[x][y]=current++; int tmpx=x,tmpy=y; for(int i=0;i<8;i++) { tmpx=x+around[i][0]; tmpy=y+around[i][1]; if(tmpx<=m&&tmpx>0&&tmpy<=n&&tmpy>0) { if(data[tmpx][tmpy]==0) { if(!dfs(tmpx,tmpy)) { data[tmpx][tmpy]=0; current--; } } } } if(current>m*n) { answer[(data[x][y]<<1)-2]=y+'A'-1; answer[(data[x][y]<<1)-1]=x+'0'; return true; } return false; } int main() { int times;scanf("%d",×); for(int ss=0;ss<times;ss++) { scanf("%d%d",&m,&n); printf("Scenario #%d:\n",ss+1); memset(data,0,sizeof(data)); current=1; memset(answer,0,sizeof(answer)); if(dfs(1,1)){printf("%s\n\n",answer);} else{printf("impossible\n\n");} } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator