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

我晕....怎么会错啊...牛人帮我看看...

Posted by rank at 2008-04-16 21:31:14 on Problem 2488
#include <iostream>
using namespace std;
int m,n,a[28][28]={0},count=0,flag,ff=1;
const int fy[9]={0,-2,-2,-1,-1,1,1,2,2};
const int fx[9]={0,-1,1,-2,2,-2,2,-1,1};
char path[678];
int pathn[678]={0};
char b[27];
void ss()
{
	int i;
	for(i=1;i<=26;i++)
		b[i]='A'+i-1;
}

void output()
{
	int j;
	cout<<"Scenario #"<<ff<<":"<<endl;
	ff++;
	for(j=1;j<=m*n;j++)
		cout<<path[j]<<pathn[j];
		cout<<endl;
		cout<<endl;
}

bool check(int x,int y)
{
	if(x>=1&&x<=m&&y>=1&&y<=n)return true;
	return false;
}
void dfs(int x,int y)
{
	int xx,yy,i;
	a[x][y]=1;
	count++;
	path[count]=b[x];
	pathn[count]=y;
	if(count==m*n)
		{
			
			output();
			flag=1;
			return;
		}
	
	for(i=1;i<=8;i++)
	{
		xx=x+fx[i];
		yy=y+fy[i];
		if(check(xx,yy)&&!a[xx][yy])
			dfs(xx,yy);			
	}
	a[xx][yy]=0;
}

int main()
{
	int i,j,test,tt;
	cin>>test;
	ss();
	while(test--)
	{
		count=0;
		flag=0;
		cin>>m>>n;
		tt=m;
		m=n;
		n=tt;	
		for(i=1;i<=m;i++)
		for(j=1;j<=n;j++)
			a[i][j]=0;
		for(i=1;i<=m;i++)
		for(j=1;j<=n;j++)
		{
			dfs(i,j);

			if(flag)
				break;
			else
			{
				count=0;
				for(i=1;i<=m;i++)
				for(j=1;j<=n;j++)
					a[i][j]=0;
			}	
		}
		if(!flag)
		{
			cout<<"Scenario #"<<ff<<":"<<endl;
			ff++;
			cout<<"impossible"<<endl;
			cout<<endl;
		}
	}	
   return 0; 
}














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