Title Link: http://www.lightoj.com/volume_showproblem.php?problem=1209
Solution: Think of several methods, are wrong, then looked at others. Get the correct posture. By voting men and women classified, the relationship between the contradictions of the edge.
Code:
#include <iostream>#include <algorithm>#include <set>#include <map>#include <string.h>#include <queue>#include <sstream>#include <stdio.h>#include <math.h>#include <stdlib.h>using namespace STD;intN, M, q;intp[510][510];intbook[510];intmatch[510];intDfsintu) { for(intv =1; V <= m; v++) {if(Book[v] = =0&& P[u][v] = =1) {Book[v] =1;if(Match[v] = =0|| DFS (Match[v])) {Match[v] = u;return 1; } } }return 0;}Chara[Ten], b[Ten];structnode{intU, V;} t1[510], t2[510];intMain () {intTintCases =1;scanf("%d", &t); while(t--) {scanf("%d%d%d", &n, &m, &q); n = m =0;memset(Match,0,sizeof(match));memset(P,0,sizeof(p)); for(inti =1; I <= Q; i++) {scanf('%s '%s ', A, b);if(a[0] ==' M ') {n++;sscanfA"%*c%d", &t1[n].u);sscanf(b,"%*c%d", &T1[N].V); }Else{m++;sscanfA"%*c%d", &t2[m].u);sscanf(b,"%*c%d", &T2[M].V); } } for(inti =1; I <= N; i++) for(intj =1; J <= m;j++) {if(t1[i].u = = T2[J].V | | t1[i].v = = t2[j].u) P[i][j] =1; }intAns =0; for(inti =1; I <= N; i++) {memset(Book,0,sizeof(book));if(Dfs (i)) ans++; }printf("Case%d:%d\n", cases++, Q-ans); }return 0;}
Copyright NOTICE: Reprint please indicate the source.
1209-strange voting "binary map matching"