HDU3729 I ' m telling the Truth (binary graph Max match)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.