HDU3729 I'm Telling the Truth(二分图最大匹配)
来源:互联网 发布:手机漏洞修复软件 编辑:程序博客网 时间:2024/06/05 05:40
传送门
题目大意:有N个学生,老师询问每个学生的排名,每个学生都告诉了一个排名区间,求可能的最多的学生说实话的个数,以及那些学生的标号,有相同的则输出字典序最大的。
建模:对于每一个学生连上对应区间的每一个点,然后求最大匹配就行了。这里有一个优化,就是当某个学生给出的排名区间的范围大于N之后就可以不用加边了,因为他肯定是可以说真话的———–PS:不加这个优化也能过
给出代码
#include<cstdio>#include<cstring>#define MAXN 100#define MAXM 110000int n, a[MAXN], b[MAXN], c[MAXM], ans[MAXN], cnt;bool ban[MAXN], vis[MAXM];bool dfs(int u){ vis[u] = 1; for(int i = 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;}int main(){ int T; scanf("%d", &T); while(T --) { cnt = 0; scanf("%d", &n);; for(int i = 1; i <= n; i ++) { scanf("%d%d", &a[i], &b[i]); ban[i] = ((b[i] - a[i]) < n); //上文所说的优化 } memset(c, 0, sizeof c); for(int i = n; i > 0; i --) if(!c[i]) { if(ban[i]) { memset(vis, 0, sizeof vis); if(dfs(i)) ans[++cnt] = i; } else ans[++cnt] = i; } printf("%d\n", cnt); for(int i = cnt; i > 1; i --) printf("%d ", ans[i]); printf("%d\n", ans[1]); } return 0;}
0 0
- hdu3729 I'm Telling the Truth(二分图最大匹配)
- HDU3729 I'm Telling the Truth(二分图最大匹配)
- hdu3729 I'm Telling the Truth【二分图匹配】
- hdu3729—I'm Telling the Truth(二分图最大匹配)
- hdu3729 I'm Telling the Truth (最大匹配)
- HDU3729 I'm Telling the Truth 匈牙利算法的二分图匹配
- hdu3729 I'm Telling the Truth
- hdu 3729 I'm Telling the Truth(二分图最大匹配,字典序最大输出)
- hdu_3729 I'm Telling the Truth 二分图匹配
- hdu 3729 I'm Telling the Truth 二分图匹配
- UVALive 5033 I'm Telling the Truth 二分图匹配
- hdu 3729 I'm Telling the Truth(二分图匹配)
- HDU 3729 I'm Telling the Truth -- 二分图最大匹配 输出方案
- hdu 3729 I'm Telling the Truth(二分图最大匹配)
- HDOJ 3729 - I'm Telling the Truth 水二分图最大匹配
- 二分图的最大匹配-hdu-3729-I'm Telling the Truth
- 二分图的最大匹配-hdu-3729-I'm Telling the Truth
- HDU 3729 I'm Telling the Truth(二分图最大匹配+结果输出)
- cocos2dx接入shareSDK分享
- cocos2dx基础篇(23)——进度条CCProgressTimer - 夏天的风 - 51CTO技术博客
- 算法竞赛入门经典--第7章,迭代加深搜索---埃及分数
- 迷之好奇 SDUTOJ 3039
- Android RecyclerView
- HDU3729 I'm Telling the Truth(二分图最大匹配)
- html部分标签学习
- js用正则表达式去除字符串左右空格
- 排序算法总结
- 将一个十六进制字符串转换为十进制数值的问题
- 【剑指Offer面试题】 九度OJ1513:二进制中1的个数
- hdu2819 swap(二分图匹配)
- Hadoop入门进阶课程3--Hadoop2.X64位环境搭建
- Oracle数据库再次安装