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

求解为什么W ,在其他题库上已经A了

Posted by 195181 at 2016-06-16 10:14:33 on Problem 2226
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=990;
int n,m,shu[maxn][maxn],heng[maxn][maxn],head[maxn<<1];
int match[maxn];
int cntn=0,cntm=0;
char s[maxn][maxn];
bool v[maxn];
struct Node
{
	int to,next;
}edge[maxn<<1];
int tot=0;
void Addedge(int x,int y)
{
	edge[++tot].to=y;
	edge[tot].next=head[x];
	head[x]=tot;
}
bool dfs(int y)
{
	for(int i=head[y];i!=-1;i=edge[i].next)
	{
		int p=edge[i].to;
		if(!v[p])
		{
			v[p]=1;
			if(  !match[p] || dfs( match[p] ) )
			{
				match[p]=y;
				return true;
			}
		}
	}
	return false;
}
int main()
{
	memset(head,-1,sizeof(head));
	memset(match,0,sizeof(match));
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%s",s[i]);
	}
	cntn=1;
	cntm=1;
	for(int i=0;i<n;i++)
	{
		int j;
		for(j=0;j<m;j++)
		{
			if(s[i][j]=='*')
			{
				while(s[i][j]=='*')
				{
					shu[i][j++]=cntn;
				}
				j--;
				cntn++;
			}
		}
	}
	for(int j=0;j<m;j++)
	{
		int i;
		for(i=0;i<n;i++)
		{
			if(s[i][j]=='*')
			{
				while(s[i][j]=='*')
				{
					heng[i++][j]=cntm;
				}	
				i--;
				cntm++;
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(s[i][j]=='*')
			{
				Addedge(shu[i][j],heng[i][j]);
			}
		}
	}
	int ans=0;
	for(int i=0;i<n*m;i++)
	{
		memset(v,0,sizeof(v));
		if( dfs(i) )ans++;
	}
	printf("%d\n",ans);
	//system("pause");
}

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