hdu 3729 I'm Telling the Truth 二分图匹配
裸的二分图匹配。需要输出方案。
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#define M 100005
#define N 65
bool vis[M];
vector<int> g[N];
int now[M];
int n,m;
int dfs(int k)
{
for(int i=0;i<g[k].size();i++)
{
int boy=g[k][i];
if(!vis[boy])
{
vis[boy]=1;
if(now[boy]==0||dfs(now[boy]))
{
now[boy]=k;
return 1;
}
}
}
return 0;
}
int main()
{
int a,b,ans;
int k;
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++) g[i].clear();
memset(now,0,sizeof(now));
int maxn=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a,&b);
maxn=max(maxn,b);
for(int j=a;j<=b;j++)
g[i].push_back(j);
}
ans=0;
for(int i=n;i>=1;i--)
{
memset(vis,0,sizeof(vis));
ans+=dfs(i);
}
printf("%d\n",ans);
int aa[66];
int top=0;
for(int i=1;i<=maxn;i++)
{
if(now[i])
{
aa[top++]=now[i];
}
}
sort(aa,aa+top);
for(int i=0;i<top;i++)
{
if(i) printf(" %d",aa[i]);
else printf("%d",aa[i]);
}
puts("");
}
return 0;
}
hdu 3729 I'm Telling the Truth 二分图匹配的更多相关文章
- hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS ( ...
- HDU 3729 I'm Telling the Truth (二分匹配)
题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹 ...
- HDU - 3729 I'm Telling the Truth(二分匹配)
题意:有n个人,每个人给出自己的名次区间,问最多有多少个人没撒谎,如果有多解,输出字典序最大的解. 分析: 1.因为字典序最大,所以从后往前分析. 2.假设后面的人没说谎,并将此作为已知条件,然后从后 ...
- UVALive 5033 I'm Telling the Truth 二分图最大匹配(略有修改)
I - I'm Telling the Truth Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- I'm Telling the Truth(二分图)
.I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 3081:Marriage Match II(二分图匹配+并查集)
http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意:有n个男生n个女生,他们只有没有争吵或者女生a与男生A没有争吵,且女生b与女生a是朋友,因此女生b也 ...
- HDU 1507 Uncle Tom's Inherited Land*(二分图匹配)
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU 4619 Warm up 2 贪心或者二分图匹配
给同一张横着的牌的所在的格子编同一样的号,这些格子对应x集合,给同一张竖着的牌所在的格子编同一样的号,对应y集合,同一个格子上既有横着的牌又有竖着的牌,那么就建一条边,有冲突就要拿走一张,结果是总的牌 ...
- HDU 5938 Kingdom of Obsession(数论 + 二分图匹配)
题意: 给定S,N,把S+1,S+2,...S+N这N个数填到1,2,...,N里,要求X只能填到X的因子的位置.(即X%Y=0,那么X才能放在Y位置) 问是否能够放满. 分析:经过小队的分析得出的结 ...
随机推荐
- 查看linux进程(强制中止进程),服务及端口号,
进程状态查询 ps -aux [test@pan ~]$ ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT START ...
- 受教了,memcache比较全面点的介绍,受益匪浅,适用memcached的业务场景有哪些?memcached的cache机制是怎样的?在设计应用时,可以通过Memcached缓存那些内容?
基本问题 1.memcached的基本设置 1)启动Memcache的服务器端 # /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 ...
- string与char* 互相转换以及周边问题
先插一个小知识点 string str = "abc" str += 'd'; cout<<str<<endl; //"abcd" ...
- hdu 2012 素数判定 Miller_Rabbin
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- [BZOJ 3995] [SDOI2015] 道路修建 【线段树维护连通性】
题目链接:BZOJ - 3995 题目分析 这道题..是我悲伤的回忆.. 线段树维护连通性,与 BZOJ-1018 类似,然而我省选之前并没有做过 1018,即使它在 ProblemSet 的第一页 ...
- Servlet 中使用POI生成Excel
使用的是poi3.13 http://mvnrepository.com/artifact/org.apache.poi/poi/3.13 import java.io.IOException; im ...
- Codeforces Round #154 (Div. 2) : B
一个很简单的题: 方法一: 二分. 代码: #include<cstdio> #include<algorithm> #define maxn 100005 using nam ...
- Windows常见蓝屏故障分析
转自Windows常见蓝屏故障分析 症状描述: 当您在运行Microsoft Windows 2000/XP/Server 2003.Microsoft Windows Vista/Server 20 ...
- March of the Penguins
poj3498:http://poj.org/problem?id=3498 题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号. 由于 ...
- KeilC51使用详解 (三)
C51强大功能及其高效率的重要体现之一在于其丰富的可直接调用的库函数,多使用库函数使程序代码简单,结构清晰,易于调试和维护,下面介绍C51的库函数系统. 第一节 本征库函数(intrinsic rou ...