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

总是WA 求哪位大神帮忙看下哪里错了 我实在不会改 测试数据没发现问题

Posted by huye at 2012-01-07 22:50:18 on Problem 2488
#include<iostream>
using namespace std;
int map[26][26],p,q;
int pathx[100],num;
char pathy[100];

int DFS(int i,int j)
{
	map[i][j] = 1;
	pathx[num] = i;
	pathy[num++] = (char)('A'+j);
	if(num == p*q) return 1;

	if(i-1>=0 && j-2>=0 && map[i-1][j-2]==0) {if(DFS(i-1,j-2)) return 1;}
	if(i+1<p && j-2>=0  && map[i+1][j-2]==0) {if(DFS(i+1,j-2)) return 1;}
	if(i-2>=0 && j-1>=0 && map[i-2][j-1]==0) {if(DFS(i-2,j-1)) return 1;}
	if(i+2<p && j-1>=0  && map[i+2][j-1]==0) {if(DFS(i+2,j-1)) return 1;}
	if(i-2>=0 && j+1<q  && map[i-2][j+1]==0) {if(DFS(i-2,j+1)) return 1;}
	if(i+2<p && j+1<q   && map[i+2][j+1]==0) {if(DFS(i+2,j+1)) return 1;}
	if(i-1>=0 && j+2<q  && map[i-1][j+2]==0) {if(DFS(i-1,j+2)) return 1;}
	if(i+1<p && j+2<q   && map[i+1][j+2]==0) {if(DFS(i+1,j+2)) return 1;}
	return 0;
}

int main()
{
	int i,j,n,count=0;
	cin>>n;
	while(count < n)
	{
		count++;
		cin>>p>>q;
		for(i = 0; i < p; i++)
		{
			for(j = 0;j < q; j++)
			{
				map[i][j] = 0;
			}
		}
		num=0;
		int flag = 0;
		cout<<"Scenario #"<<count<<":"<<endl;
		for(i = 0; i < p;i++)
		{
			for(j = 0; j < q;j++)
			{
				if(DFS(i,j))
				{
					for(i = 0;i < num; i++)
						cout<<pathy[i]<<pathx[i]+1;
					cout<<endl<<endl;
					flag = 1;
					break;
				}
			}
			if(flag) break;
		}
		if(flag) continue;
		cout<<"impossible"<<endl<<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