Transmission Door
The main topic: There are n students, the teacher asked each student's ranking, each student told a ranking interval, the most likely students to tell the number of the truth, as well as those students of the label, have the same output dictionary order the largest.
Modeling: For each student to connect to each point of the corresponding interval, and then to find the best match on the line. Here is an optimization, that is, when a student gives a range of rankings greater than n can not add edge, because he must be able to tell the truth ——— –ps: No, this optimization can also be
Give the Code
#include <cstdio>#include <cstring>#define MAXN#define MAXM 110000intN, A[maxn], B[MAXN], C[MAXM], ANS[MAXN], CNT;BOOLBAN[MAXN], VIS[MAXM];BOOLDfsintu) {Vis[u] =1; for(inti = A[u] + N; I <= B[u] + N; i + +) {if(Vis[i])Continue; Vis[i] =1;if(!c[i] | | DFS (C[I)) {C[u] = i; C[i] = u;return 1; } }return 0;}intMain () {intTscanf("%d", &t); while(T-) {cnt =0;scanf("%d", &n);; for(inti =1; I <= N; i + +) {scanf("%d%d", &a[i], &b[i]); Ban[i] = ((B[i]-a[i]) < n);//The optimization described above}memsetC0,sizeofc); for(inti = n; i >0; I--)if(!c[i]) {if(Ban[i]) {memset(Vis,0,sizeofVIS);if(Dfs (i)) ans[++cnt] = i; }ElseANS[++CNT] = i; }printf("%d\n", CNT); for(inti = CNT; i >1; I--)printf("%d", Ans[i]);printf("%d\n", ans[1]); }return 0;}
Copyright NOTICE: Please feel free to reprint O (∩_∩) o
HDU3729 I ' m telling the Truth (binary graph Max match)