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 dreamone at 2007-10-06 09:58:44 on Problem 1315
#include<iostream>
using namespace std;
int i,j,ans,n,row,col;
char ch;
char value[5][5];
bool ok(int row,int col)
{
	for(i=row-1;i>=0;i--)
	{
		if(value[i][col]=='o')
			return false;
		if(value[i][col]=='X')
			break;
	}
	for(j=col-1;j>=0;j--)
	{
		if(value[row][j]=='o')
			return false;
		if(value[col][j]=='X')
			break;
	}
	return true;
}
void search(int x,int y)
{
	if(x==n*n)
	{
		if(y>ans)
			ans=y;
     	 return ;
	}
	else
	{
		row=x/n;
		col=x%n;
		if(value[row][col]=='.'&&ok(row,col))
		{
			value[row][col]='o';
			search(x+1,y+1);
			value[row][col]='.';
		}
		search(x+1,y);
	}
}
int main()
{
	while(cin>>n)
	{
		if(n==0)
			break;
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
			{
				cin>>value[i][j];
			}
		ans=0;
		search(0,0);//第一个参数表示从第几个位置,第二个参数表示的是放了几个城堡
		cout<<ans<<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