| ||||||||||
| 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:求大神帮助。。。 代码错误在哪里,我测试的数据都是正确的,就是不给过。。In Reply To:求大神帮助。。。 代码错误在哪里,我测试的数据都是正确的,就是不给过。。 Posted by:wangfeichi at 2012-08-01 17:47:54 > #include <iostream>
using namespace std;
int visit[10][10];
bool judge;
struct path {int x;int y;};
int next[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};
path result[64];
int num,latin;
void findpath(int i,int j,int Count)
{
if(judge==1) return;
int p,q;
visit[i][j]=1;
result[Count-1].x=i;
result[Count-1].y=j;
if(Count==num*latin)
{
judge=1;
return;
}
for(int a=0;a<8;a++)
{
p=i+next[a][0];
q=j+next[a][1];
if(p<latin && p>=0 && q>=0 && q<num)
if(visit[p][q]==0)
{
findpath(p,q,Count+1);
if(judge) return;
else{
visit[i][j]=0;
}
}
}
return;
}
int main()
{
int n;
int a,b,c=1,d;
cin>>n;
while(c<=n)
{
judge=0;
for(a=0;a<10;a++)
for(b=0;b<10;b++)
visit[a][b]=0;
cin>>num>>latin;
if(num*latin>26 || num*latin<1) continue;
findpath(0,0,1);
cout<<"Scenario #"<<c<<":"<<endl;
if(!judge) cout<<"impossible";
else for(d=0;d<num*latin;d++) cout<<char('A'+result[d].x)<<result[d].y+1;
cout<<endl<<endl;
c++;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator