hdu 3729 I'm Telling the Truth
来源:互联网 发布:特价专场首页淘宝优站 编辑:程序博客网 时间:2024/05/16 06:53
acm.hdu.edu.cn/showproblem.php?pid=3729
要求输出字典序最大的那个结果 所以逆向进行二分匹配。
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;int n,l,r,G[61][100010],t[61],cnt;int check[100010],ma[61],mb[100010];int DFS(int u){ for(int i=l; i<=r; i++){ if(!check[i] && G[u][i] > 0){ check[i] = 1; if(mb[i] == -1 || DFS(mb[i])){ ma[u] = i; mb[i] = u; return 1; } } } return 0;}int MMC(){ int res = 0; memset(ma,-1,sizeof(ma)); memset(mb,-1,sizeof(mb)); for(int i=n; i>=1; i--){ memset(check, 0, sizeof(check)); res += DFS(i); } return res;}int main(){ int cas; scanf("%d",&cas); while(cas--){ scanf("%d",&n); l = 1e9, r = -1; memset(G, 0, sizeof(G)); for(int i=1; i<=n; i++){ int a,b; scanf("%d%d",&a,&b); for(int j=a; j<=b; j++){ G[i][j] = 1; r = max(r, j); l = min(l, j); } } int ans = MMC(); printf("%d\n",ans); cnt = 0; for(int i=l; i<=r; i++) if(mb[i] != -1) t[cnt++] = mb[i]; sort(t, t + cnt); cout << t[0]; for(int i=1; i<cnt; i++) cout << " " << t[i]; cout << endl; } return 0;}
0 0
- HDU 3729 I'm Telling the Truth
- HDU 3729 I'm Telling the Truth
- HDU 3729I'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
- I'm Telling the Truth HDU
- I'm Telling the Truth HDU
- hdu 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(贪心)
- HDU 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(入门级别)
- hdoj 3729 I'm Telling the Truth
- HOJ 3729 I'm Telling the Truth
- spring transaction 失效问题
- Android ndk-stack tool使用
- sublime text 自己常用的快捷键
- Linux makefile 教程 非常详细,且易懂
- PHP下载网页
- hdu 3729 I'm Telling the Truth
- 手机卫士学习06-自定义滚动的TextView实现走马灯效果
- ASCII编码与Unicode编码
- onActivityResult传值
- 新股集合竞价
- 制作dll和测试dll
- 关于apache FTP下载速度慢的解决方案
- 什么是编程语言
- 理财如何越理越有钱 朝气蓬勃的2015该如何实现理财计划?