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了20多次,受不了了,求各位路过的指教下

Posted by liuhighway at 2011-05-02 16:52:49 on Problem 2446
#include<iostream>
#include<cstring>
#define n 50*50
int visy[n],conny[n];
int mat[n][n];
int c,m;
int kong[n][2];
int all;
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
using namespace std;

bool find (int t)
{
	int i;
	for(i=0;i<all;i++)
	{
		if(visy[i]==0&&mat[t][i]==1)
		{
			visy[i]=1;
			if(conny[i]==-1||find(conny[i]))
			{
				conny[i]=t;
				return true;
			}
		}
	}
	return false;
}
bool ok( int a,int b)
{
	if(a>=0&&a<c&&b>=0&&b<m&&mat[a][b]!=-1) return true;
	return false;
}
bool judge(int a,int b,int a1,int b1)
{
	if(a==a1&&abs(b-b1)==1) return true;
	else 
		if(b==b1&&abs(a-a1)==1) return true;
		else return false;
}

int main()
{
	int num;
	int i,j,k;

	while(scanf("%d%d%d",&c,&m,&num)==3)
	{
		

	 memset(mat,0,sizeof(mat));
	memset(conny,-1,sizeof(conny));
	for(i=0;i<num;i++)
		{
			scanf("%d%d",&kong[i][0],&kong[i][1]);
			
			mat[kong[i][1]-1][kong[i][0]-1]=-1;
	    }
	if((c*m-num)%2==1)
		{cout<<"NO"<<endl;continue;}
    all=c*m;
	int a,b;
	int a1,b1;
	for(i=0;i<all;i++)
	{		if(i%2==1)continue;
			a=i/m;
			b=i%m;			
			if(mat[a][b]!=-1)
			{
				for(k=0;k<4;k++)
				{
					a1=a+dir[k][0]; //a 是第几行
					b1=b+dir[k][1]; //b是第几列
					if(ok(a1,b1)&&judge(a,b,a1,b1))
						mat[i][a1*m+b1]=1;
				}
			
		    }
	}
	/*for(i=0;i<all;i++)
	{
		for(j=0;j<all;j++)
		{
			if(mat[i][j]==1)
				cout<<i<<" "<<j<<endl;
		}
	}*/
	int tot=0;
	for(i=0;i<all;i++)
	{
		memset(visy,0,sizeof(visy));
		if(find(i)) tot++;
	}
	//cout<<tot<<endl;
	if(tot*2+num==c*m) cout<<"YES"<<endl;
	else cout<<"NO"<<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