Test instructions: Some women and some men have a good opinion, have a good feeling can ride a roller coaster, ask the most can compose how many
HDU 11 page on the few algorithm problems, two-figure matching problem, Hungarian algorithm, for each man, see and he has a good sister there is no pairing, no pairing can be successful pairing, if it has been paired, look at that sister matched man can find a sister who is not paired, If you can break up the current pairing recombination pairing, otherwise it will not be dismantled; if all the good girls still fail to match, the man is doomed to be lonely for a lifetime.
1#include <stdio.h>2#include <string.h>3 intnow,head[1001],next[1001],point[1001],visit[1001],match[1001];4 5 voidAddintXinty) {6next[++now]=Head[x];7head[x]=Now ;8point[now]=y;9 }Ten One intDfsintk) A { - for(intI=head[k];i;i=next[i])if(!Visit[point[i]]) { - intp=Point[i]; thevisit[p]=1; - if(match[p]==-1||DFS (match[p])) { -match[p]=K; - return 1; + } - } + return 0; A } at - intMain () { - intK,m,n; - while(SCANF ("%d", &k)!=eof&&k!=0){ -scanf"%d%d",&m,&N); -memset (match,-1,sizeof(Match)); inMemset (Head,0,sizeof(head)); -now=0; to inti,ans=0; + for(i=1; i<=k;i++){ - intb; thescanf"%d%d",&a,&b); * Add (A, b); $ }Panax Notoginseng for(i=1; i<=m;i++){ -memset (Visit,0,sizeof(visit)); the if(Dfs (i) = =1) ans++; + } Aprintf"%d\n", ans); the } + return 0; -}
View Code
HDU 20,632-point map matching