HDU 3729 I'm Telling the Truth(2010 Asia Tianjin Regional Contest )
来源:互联网 发布:彩票pk10开奖网源码 编辑:程序博客网 时间:2024/06/07 05:27
【题目链接】http://acm.hdu.edu.cn/showproblem.php?pid=3729
【解题报告】
做这场比赛的时候还不会二分图匹配,全场想构造贪心解法TAT。实际上如果会二分图匹配的话这道题目还是挺裸的。需要注意的是给出的x,y范围非常大,也就是图非常稀疏,用邻接矩阵不可避免会T的。所以我开了一个结构体用来存边集,实测62ms就过了。
【参考代码】
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxs=1e5+10;bool vis[maxs];int link[maxs],used[61];int n;struct node{ int x,y;}mp[61];bool DFS( int u ){ for( int i=mp[u].x; i<=mp[u].y; i++ ) if( !vis[i] ) { vis[i]=1; if( link[i]==-1 || DFS( link[i] ) ) { link[i]=u; used[u]=1; return true; } } return false;}int main(){ int T; cin>>T; while( T-- ) { memset( link,-1,sizeof(link)); memset( used,0,sizeof(used)); scanf( "%d",&n ); for( int i=1; i<=n; i++ ) { int x,y; scanf("%d%d",&x,&y); mp[i].x=x; mp[i].y=y; } int ans=0; for( int i=n; i>=1; i-- ) { memset( vis, 0, sizeof(vis) ); if( DFS(i) )ans++; } printf("%d\n",ans); int tt=ans; for( int i=1; i<=n; i++ )if(used[i]) { tt--; if(tt)printf("%d ",i ); else printf("%d\n",i); } } return 0;}
0 0
- HDU 3729 I'm Telling the Truth(2010 Asia Tianjin Regional Contest )
- hdu 3729 2010 Asia Tianjin Regional Contest
- 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
- 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【二分匹配】
- WebStorm Tomcat 调试 js
- ADB的使用
- 使用LinkedList来模拟堆栈或队列数据结构
- Microsoft Visual C++ 6.0快捷键(绝对值得掌握)
- IOS中获取各种文件的目录路径的方法
- HDU 3729 I'm Telling the Truth(2010 Asia Tianjin Regional Contest )
- nyoj 448 寻找最大数
- 空格替换
- 【搜索】 HDU 4474 Yet Another Multiple Problem
- IOS的app程序中的文件目录的功能和使用详细说明 - 包括itune同步的部分
- Android的Activity滑动切换动画
- 前序为ABC,后序为CBA的二叉树共有多少棵
- PHP 学习2
- XSD、dtd不联网情况下可能出现的报错。