UVALive 5033 I'm Telling the Truth
来源:互联网 发布:单片机输出电压不恒定 编辑:程序博客网 时间:2024/05/16 01:47
题解及代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define maxn 11111using namespace std;typedef long long ll;int match[100010];int chk[100010],n;int st[66];struct node{ int l,r;}map[62];int dfs(int p){ int i,t; for(int i=map[p].l;i<=map[p].r;i++) if(!chk[i]) { chk[i]=1; t=match[i]; match[i]=p; if(t==-1||dfs(t)) return 1; match[i]=t; } return 0;}int Pro(){ int i,res=0; for(int i=n;i>=1;i--) //字典序最大从n到1遍历,字典序最小从1到n遍历 { memset(chk,0,sizeof(chk)); res+=dfs(i); } return res;}int main(){ memset(map,0,sizeof(map)); int t; cin>>t; while(t--) { scanf("%d",&n); memset(match,-1,sizeof(match)); for(int i=1;i<=n;i++) { scanf("%d%d",&map[i].l,&map[i].r); } printf("%d\n",Pro()); int k=0; for(int i=1;i<=n;i++) { for(int j=map[i].l;j<=map[i].r;j++) if(match[j]>0) { st[k++]=match[j]; match[j]=-1; } } sort(st,st+k); for(int i=0;i<k;i++) if(i<k-1) { printf("%d ",st[i]); } else printf("%d\n",st[i]); } return 0;}/*二分图最大匹配的题目,直接使用模版就行了,这里主要是求出字典序最大的序列,直接在代码中进行小修改就行了,在代码中给出了需要注意的地方。*/
0 0
- UVALive 5033 I'm Telling the Truth
- UVALive 5033 I'm Telling the Truth 二分图匹配
- I'm Telling the Truth
- hdoj 3729 I'm Telling the Truth
- 天津 2010 I'm telling the truth
- HDU 3729 I'm Telling the Truth
- HDU 3729 I'm Telling the Truth
- hdu3729 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
- I'm Telling the Truth(二分图)
- HOJ 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 3279 I'm Telling the Truth 二分匹配
- hdu 3729 I'm Telling the Truth(最大匹配)
- hdu-oj 1408 盐水的故事
- Win7 加载Grub
- 单例的设计与作用
- JavaScript学习 jquery学习8 事件处理
- C语言考试
- UVALive 5033 I'm Telling the Truth
- BOJ 2014新生暑假个人排位赛07 整合
- LA 6662 —— The Last Ant(模拟)
- Hibernate对视图的映射
- 【Agile Pair Coding】Data Type Mapping
- hdoj 2087 剪花布条
- ios--UITabBarController的用法
- iocp详解
- OC 中的数组方法(不可变数组NSArray 和 可变数组 NSMutableArray)