UVa live3415Guardian of Decency(二分最大匹配之最大独立点集)
来源:互联网 发布:医院预约管理系统php 编辑:程序博客网 时间:2024/05/01 13:42
题目地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1416
Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an
excursion, but he is afraid that some of them might become couples. While you can never exclude this
possibility, he has made some rules that he thinks indicates a low probability two persons will become
a couple:
Their height differs by more than 40 cm.
They are of the same sex.
Their preferred music style is different.
Their favourite sport is the same (they are likely to be fans of different teams and that would
result in ghting).
So, for any two persons that he brings on the excursion, they must satisfy at least one of the
requirements above. Help him nd the maximum number of persons he can take, given their vital
information.
Input
The rst line of the input consists of an integer T 100 giving the number of test cases. The rst line
of each test case consists of an integer N 500 giving the number of pupils. Next there will be one
line for each pupil consisting of four space-separated data items:
an integer h giving the height in cm;
a character `F' for female or `M' for male;
a string describing the preferred music style;
a string with the name of the favourite sport.
No string in the input will contain more than 100 characters, nor will any string contain any
whitespace.
Output
For each test case in the input there should be one line with an integer giving the maximum number
of eligible pupils.
Sample Input
2
4
35 M classicism programming
0 M baroque skiing
43 M baroque chess
30 F baroque soccer
8
27 M romance programming
194 F baroque programming
67 M baroque ping-pong
51 M classicism programming
80 M classicism Paintball
35 M baroque ping-pong
39 F romance ping-pong
110 M romance Paintball
Sample Output
3
7
这题是大白书上的习题,一道最大独立点集。建图药反建,不符合要求的的连一条边,最终求得的最大独立点集就是满足要求的最多的。代码如下:
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <algorithm>using namespace std;struct node{ int u, v; int next;}edge[500000];struct N{ int high; char c; char s1[200]; char s2[200];}ren[5000];int head[1000], link[1000], vis[1000], n, cnt;void add(int u, int v){ edge[cnt].v=v; edge[cnt].next=head[u]; head[u]=cnt++;}int dfs(int u){ int i; for(i=head[u];i!=-1;i=edge[i].next) { int v=edge[i].v; if(!vis[v]) { vis[v]=1; if(link[v]==-1||dfs(link[v])) { link[v]=u; return 1; } } } return 0;}void hungary(){ int i, ans=0; memset(link,-1,sizeof(link)); for(i=0;i<n;i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) ans++; } printf("%d\n",n-ans/2);}int main(){ int i, j, t; scanf("%d",&t); while(t--) { cnt=0; memset(head,-1,sizeof(head)); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %c %s %s",&ren[i].high,&ren[i].c,ren[i].s1,ren[i].s2); for(j=0;j<i;j++) { if(abs(ren[i].high-ren[j].high)<=40&&ren[j].c!=ren[i].c&&!strcmp(ren[i].s1,ren[j].s1)&&strcmp(ren[i].s2,ren[j].s2)) { add(i,j); add(j,i); } } } hungary(); } return 0;}
- UVa live3415Guardian of Decency(二分最大匹配之最大独立点集)
- poj2771Guardian of Decency 二分匹配之最大独立集
- Guardian of Decency - UVa 12083 二分图最大独立点集
- UVA 12083 - Guardian of Decency(二分图最大匹配)
- LA - 3415 - Guardian of Decency(二分图最大独立点集)
- POJ 2771 Guardian of Decency(最大独立点集)
- POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)
- POJ 2771 Guardian of Decency(最大独立集、二分图匹配)
- POJ 2771 Guardian of Decency(二分图最大独立集)
- POJ 2771 Guardian of Decency(二分图最大独立集)
- POJ 2771 Guardian of Decency(二分图最大独立集)
- UVALive3415[Guardian of Decency] 二分图最大独立集模型
- LA 3415 Guardian of Decency (二分图最大独立集)
- UVA 12083 Guardian of Decency(最大独立集)
- UVALive 3415 Guardian of Decency(二分图最大独立集)
- POJ-2771-Guardian of Decency-求二分图最大独立集(匈牙利算法)
- POJ2771Guardian of Decency最大独立集
- POJ 2771 Guardian of Decency (最大独立集Hungary)
- 判断线段相交
- JSP的转义字符
- shell算数表达式运算
- No grammar constraints (DTD or XML schema)
- 动态表单实现客户端二次过滤及字段汇总统计
- UVa live3415Guardian of Decency(二分最大匹配之最大独立点集)
- Java8新特性——可重复注解
- Android常见的错误及解决
- 2862--勾股定理
- java实现Img与PDF相互转换
- memset()函数的应用
- A*算法(转)
- SWF 文件不能访问本地资源
- 利用Robot Framework和Python wrapper of Android uiautomator的Android测试自动化