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

为什么将cnt从500改到1000就对了???

Posted by jerrywans119 at 2018-04-04 16:49:40 on Problem 2239
代码:
#include<cstdio>
#include<cstring>

const int N=5000+5;

using namespace std;

int g[10][20];
int head[N],nxt[N],to[N],cn;
int link[N];
int n,t,p,q,ans,cnt=1000;
bool vis[N];

void init(){
	ans=cn=0;
	memset(link,0,sizeof(link));
	memset(head,0,sizeof(head));
	memset(nxt,0,sizeof(nxt));
	memset(to,0,sizeof(to));
}

void create(int u,int v){
	cn++;
	to[cn]=v;
	nxt[cn]=head[u];
	head[u]=cn;
}

bool find(int x){
	int v;
	for(int i=head[x];i;i=nxt[i]){
		v=to[i];
		if(!vis[v]){
			vis[v]=true;
			if((!link[v]) || (find(link[v]))){
				link[v]=x;
				return true;
			}
		}
	}
	return false;
}

int main(){
	for(int i=1;i<=7;i++)
	    for(int j=1;j<=12;j++)
			g[i][j]=++cnt;
	while(scanf("%d",&n)==1){
		init();
		for(int i=1;i<=n;i++){
			scanf("%d",&t);
			for(int j=1;j<=t;j++){
				scanf("%d%d",&p,&q);
				create(i,g[p][q]);
			}
		}
		
		for(int i=1;i<=n;i++){
			memset(vis,false,sizeof(vis));
			if(find(i))
				ans++;
		}
		printf("%d\n",ans);
	}
	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