博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1068 Girls and boys
阅读量:5267 次
发布时间:2019-06-14

本文共 2805 字,大约阅读时间需要 9 分钟。

Girls and Boys

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 13402    Accepted Submission(s): 6293

Problem Description
the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been “romantically involved”. The result of the program is the number of students in such a set.
The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description:
the number of students
the description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:(0)
The student_identifier is an integer number between 0 and n-1, for n subjects.
For each given data set, the program should write to standard output a line containing the result.
Sample Input
7 0: (3) 4 5 6 1: (2) 4 6 2: (0) 3: (0) 4: (2) 0 1 5: (1) 0 6: (2) 0 1 3 0: (2) 1 2 1: (1) 0 2: (1) 0
 
Sample Output
5 2
裸的二分匹配,但是我却去写最大流了2333333,真的傻,还调试了一阵子。。
借这个题学习了一下匈牙利算法。。现在写题都注重板子了23333
建两个集合,跑一遍匈牙利算法就行了
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 using namespace std;20 typedef struct Edge {21 int u, v, c, next;22 }Edge;23 const int inf = 0x7f7f7f7f;24 const int maxn = 10000;25 #define maxm 3000026 #define ll long long27 #define debug(x) cout<<"x="<
<
'9')34 {35 if(ch=='-') f=-1;36 ch=getchar();37 }38 while(ch>='0'&&ch<='9')39 {40 x=10*x+ch-'0';41 ch=getchar();42 }43 return x*f;44 }45 int n,m,s,t,tot=0,head[maxn],l,r,match[maxn];46 bool vis[maxn];47 struct edge{ int to,next;}e[maxm];48 void ins(int x,int y){e[tot].to=y;e[tot].next=head[x];head[x]=tot++;}49 bool dfs(int u)50 {51 for(int i=head[u];i!=-1;i=e[i].next)52 {53 int v=e[i].to;54 if(vis[v]) continue;55 vis[v]=true;56 if(match[v]==-1||dfs(match[v]))57 {58 match[v]=u;59 return true;60 }61 }62 return false;63 }64 int hungary(int x,int y)65 {66 l=x;r=y;67 int ans=0;68 mem(match,-1);69 for(int u=1;u<=l;++u)70 {71 mem(vis,0);72 if(dfs(u)) ans++;73 }74 return ans;75 }76 void init()77 {78 mem(head,-1);79 tot=0;80 }81 int main() {82 int k;83 while(~scanf("%d",&k)&&k){84 init();85 for(int i=0;i

 

转载于:https://www.cnblogs.com/TYH-TYH/p/9437526.html

你可能感兴趣的文章
使用XML传递数据
查看>>
TYVJ.1864.[Poetize I]守卫者的挑战(概率DP)
查看>>
基于CMMI的敏捷开发过程文档裁剪
查看>>
0925 韩顺平java视频
查看>>
软件需求规格说明书
查看>>
53. Maximum Subarray
查看>>
iOS-程序启动原理和UIApplication
查看>>
SpringMVC入门(二)—— 参数的传递、Controller方法返回值、json数据交互、异常处理、图片上传、拦截器...
查看>>
git的安装
查看>>
mysql 8.0 zip包安装
查看>>
Spring框架系列(三)--Bean的作用域和生命周期
查看>>
springboot + mybatis
查看>>
awk 统计
查看>>
CSS min-height 属性
查看>>
模板设计模式的应用
查看>>
实训第五天
查看>>
平台维护流程
查看>>
2012暑期川西旅游之总结
查看>>
Linux发行版的排行
查看>>
12010 解密QQ号(队列)
查看>>