POJ-2771 Guardian of Decency binary chart maximum matches

Source: Internet
Author: User

The main topic: There are n individuals to participate in an activity, the activities required to participate in the people try not to have couples, organizers proposed four ways to reduce couples:
1. Two people with a height difference greater than 40
2. Same gender
3. Like different styles of music
4. Like the same sport
As long as one of them is satisfied, the two are not couples.
Now give the four data of n individuals, ask the maximum number of people who can be invited

Problem-solving ideas: This problem and POJ 1466 Girls and boys The question is very similar, but this problem gives the condition is not directly given, but we have to find the
As long as two people four conditions are not satisfied, you can think that they are couples (equivalent to POJ 1466 this problem of the secret love Relationship). So, find out 22 between the 4 conditions are not satisfied with the relationship, then this question and POJ 1466 this question very much like, then this question becomes to give a certain secret love relationship, ask you to find M personal, this m person of any two people is not a secret love relationship.

#include <cstdio>#include <cstring>#include <vector>#include <cstdio>using namespace STD;Const intN =510;Const intMAXN = the;structperson{intHeightCharSexCharSTYLE[MAXN], SPORT[MAXN]; }p[n];intn, Link[n],vis[n]; vector<int>G[n];voidInit () {scanf("%d", &n); for(inti =0; I < n; i++) {scanf("%d%c%s%s", &p[i].height, &p[i].sex, P[i].style, P[i].sport);    G[i].clear (); } for(inti =0; I < n; i++) for(intj =0; J < N; J + +)if(I! = j) {if( ! ((P[i].height-p[j].height) > +|| P[j].height-p[i].height > +|| P[i].sex = = P[j].sex | |strcmp(p[i].style,p[j].style)! =0||strcmp(P[i].sport, p[j].sport) = =0)) G[i].push_back (j); }memset(Link,-1,sizeof(link));}BOOLDfsintu) { for(inti =0; I < g[u].size (); i++) {if(Vis[g[u][i]])Continue; Vis[g[u][i]] =1;if(Link[g[u][i]] = =-1|| DFS (Link[g[u][i]])) {Link[g[u][i]] = u;return true; }    }return false;}voidHungary () {intAns =0; for(inti =0; I < n; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", N-ans/2);}intMain () {intTestscanf("%d", &test); while(test--)        {init ();    Hungary (); }return 0;}

POJ-2771 Guardian of Decency binary chart maximum matches

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.