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 louchiheng at 2016-03-27 12:49:28 on Problem 3020
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int n,m,p,i,j,x,y,ans,t,r[1000],a[1000][1000];
bool b[1000],map[1000][1000],g[1000];
char ch;
bool dfs(int k)
{
	g[k]=1;
	for(int j=1;j<=n;++j)
	if(map[k][j])
	{
		if(!b[j])
		{
			b[j]=1;
			r[j]=k;
			return 1;
		}
		if(!g[r[j]]&&dfs(r[j]))
		{
			b[j]=1;
			r[j]=k;
			return 1;
		}
	}
	return 0;
}
int main()
{
	cin>>t;
	for(p=1;p<=t;++p)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(map,0,sizeof(map));
		ans=0;
		n=0;
		cin>>x>>y;
		for(i=1;i<=x;++i)
		for(j=1;j<=y;++j)
		{
			cin>>ch;
			if(ch=='*')
			{
				n++;
				a[i][j]=n;
			}
		}
		for(i=1;i<=x;++i)
		for(j=1;j<=y;++j)
		{
			if(a[i][j-1]>0)map[a[i][j]][a[i][j-1]]=1;
			if(a[i][j+1]>0)map[a[i][j]][a[i][j+1]]=1;
			if(a[i-1][j]>0)map[a[i][j]][a[i-1][j]]=1;
			if(a[i+1][j]>0)map[a[i][j]][a[i+1][j]]=1;
		}
		for(i=1;i<=n;++i)
		{
			memset(g,0,sizeof(g));
		    if(dfs(i))ans++;
		}
		ans=n-ans/2;
		cout<<ans<<endl;
	}
}

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