HDU 3729 I'm Telling the Truth(入门级别)
来源:互联网 发布:网络机顶盒 电视台 编辑:程序博客网 时间:2024/06/05 10:50
好久没写博客了…= =;现在慢慢补上
如有错误,欢迎大牛指出!!
最近开始着手图论的学习,感觉建图是个关键啊!!这道题目倒还好,最大二分图的匹配问题,最后输出是最大字典序输出,注意一下就好。
题解:基本上属于模板题,搜索的时候可以反向匹配就好了。
本来想用STL里面的set集合来输出的,莫名WA不知道为何…求大牛解救。
后来只好中规中矩的用数组了;
ac code:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s) scanf("%s",s)#define pi1(a) printf("%d\n",a)#define pi2(a,b) printf("%d %d\n",a,b)#define mset(a,b) memset(a,b,sizeof(a))#define forb(i,a,b) for(int i=a;i<b;i++)#define ford(i,a,b) for(int i=a;i<=b;i++)typedef long long LL;const int N=1100001;const int M=6666666;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-7;bool vis[100010];int linker[100010];int ss[70];struct node{ int x,y;}a[70];int dfs(int u){ for(int i=a[u].x;i<=a[u].y;i++) { if(!vis[i]) { vis[i]=1; if(linker[i]==-1||dfs(linker[i])) { linker[i]=u; ss[u]=1; return 1; } } } return 0;}int main(){ int T; si1(T); while(T--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i].x,&a[i].y); } int sum=0; mset(linker,-1); mset(ss,0); for(int i=n;i>0;i--) { mset(vis,0); sum+=dfs(i); } printf("%d\n",sum); int i; for(i=1;i<n;i++) if(ss[i]==1) printf("%d ",i); printf("%d\n",i); } return 0;}
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cstdlib>#include <cmath>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;#define si1(a) scanf("%d",&a)#define si2(a,b) scanf("%d%d",&a,&b)#define sd1(a) scanf("%lf",&a)#define sd2(a,b) scanf("%lf%lf",&a,&b)#define ss1(s) scanf("%s",s)#define pi1(a) printf("%d\n",a)#define pi2(a,b) printf("%d %d\n",a,b)#define mset(a,b) memset(a,b,sizeof(a))#define forb(i,a,b) for(int i=a;i<b;i++)#define ford(i,a,b) for(int i=a;i<=b;i++)typedef long long LL;const int N=1100001;const int M=6666666;const int INF=0x3f3f3f3f;const double PI=acos(-1.0);const double eps=1e-7;bool vis[100010];int linker[100010];set < int > s;struct node{ int x,y;}a[70];int dfs(int u){ for(int i=a[u].x;i<=a[u].y;i++) { if(!vis[i]) { vis[i]=1; if(linker[i]==-1||dfs(linker[i])) { linker[i]=u; s.insert(u); return 1; } } } return 0;}int main(){ int T; si1(T); while(T--) { s.clear(); int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i].x,&a[i].y); } int sum=0; mset(linker,-1); for(int i=n;i>0;i--) { mset(vis,0); sum+=dfs(i); } printf("%d\n",sum); set<int >::iterator it; for(it=s.begin();it!=s.end();it++) { if(++it==s.end()) break; //printf("d "); it--; cout<<*it<<' '; } it++; cout<<*it<<endl; } return 0;}
0 0
- HDU 3729 I'm Telling the Truth(入门级别)
- 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(最大匹配)
- 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【二分匹配】
- hdoj 3729 I'm Telling the Truth
- HOJ 3729 I'm Telling the Truth
- Unity 4.6升级到Unity 5,遇到3个GetTriangleStrip 相关warning的解决方法
- 再试算法----穷举法
- 关于多个用户对一个文件进行操作的时候
- 赛码网:翻转数组,C语言
- 系统安装
- HDU 3729 I'm Telling the Truth(入门级别)
- 从选择一本书开始
- 11、Java入门-简易扑克牌游戏
- iOS 相机调用后为英文的解决办法
- 宏定义函数
- C语言中关于字符数组和指针数组
- Linux(Ubuntu)常用命令--学习笔记
- Android 模仿新闻顶部导航标签
- js个人笔记3