| ||||||||||
| 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 | |||||||||
求被看看程序哪里错了,一直wa,样例都过了啊#include <iostream>
#include <cstring>
using namespace std;
int length,wide,N,step,pointer;
char ways[730];
bool chessboard[35][35];
void push_way(int i,int j)
{
ways[pointer++]=static_cast<char>(i+'A');
ways[pointer++]=static_cast<char>(j+1+'0');
}
void pop_way()
{
ways[pointer--]=0;
ways[pointer--]=0;
}
int direction[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}; //字典序先往上头跳,再往下头跳
bool DFS(int i,int j)
{
if( i>=0 && j>=0 && i<wide && j<length && !chessboard[i][j] )
{
push_way(i,j);
chessboard[i][j]=1;
++step;
}
else return 0;
if(step==length*wide)return 1;
for (int ix=0;ix!=8;++ix)
{
int di=i+direction[ix][0];
int dj=j+direction[ix][1];
if(DFS(di,dj))return 1;
}
pop_way();
chessboard[i][j]=0;
--step;
return 0;
}
int main()
{
cin>>N;
for(int ii=1;ii!=N+1;++ii)
{
step=0,pointer=0;
memset(chessboard,0,sizeof(chessboard));
memset(ways,0,sizeof(ways));
cin>>length>>wide;
if(DFS(0,0))cout<<"Scenario #"<<ii<<endl<<ways<<endl;
else cout<<"Scenario #"<<ii<<":"<<endl<<"impossible"<<endl;
cout<<endl;
}
return 0;
}
要疯了,要疯了~~~~~~~~~~
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator