题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=3729

题目意思:

有n个学生,老师询问每个学生的排名,每个学生都告诉了一个排名区间,求可能的最多的学生说实话的个数,以及那些学生的标号,有相同的则输出字典序最大的。

解题思路:

这题贪心只能求出个数,但要求字典序最大,则须用二分匹配。

将学生标号放到一个集合A里,另外一个集合B放排名。对于每个学生可能在的排名点,建一条边。从学生标号大的开始匹配。

代码

#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std; #define Maxn 65
#define Maxm 110000 int cx[Maxn],cy[Maxm],nx,ny;
bool vis[Maxm];
vector<int>g[Maxn]; int path(int u)
{
for(int v=0;v<g[u].size();v++)
{
if(!vis[g[u][v]])
{
vis[g[u][v]]=true; //从这个点找,要么找到对应的,要么找不到
if(cy[g[u][v]]==-1||path(cy[g[u][v]]))
{
cy[g[u][v]]=u;
cx[u]=g[u][v];
return 1;
}
}
}
return 0;
}
int MaxMatch()
{
memset(cx,-1,sizeof(cx));
memset(cy,-1,sizeof(cy)); int ans=0;
for(int i=nx;i>=1;i--) //满足字典序最大
{
if(cx[i]==-1)
{
memset(vis,false,sizeof(vis));
ans+=path(i);
}
}
return ans;
}
int main()
{
int t; scanf("%d",&t);
while(t--)
{
scanf("%d",&nx); for(int i=1;i<=nx;i++)
{
g[i].clear();
int a,b;
scanf("%d%d",&a,&b);
for(int j=a;j<=b;j++) //将所有的可能排名点建一条边
g[i].push_back(j);
}
int ans=MaxMatch();
printf("%d\n",ans);
for(int i=1;i<=nx;i++)
{
if(cx[i]!=-1)
{
printf("%d",i);
ans--;
if(ans)
putchar(' ');
else
putchar('\n');
}
}
}
return 0;
}

二分图的最大匹配-hdu-3729-I'm Telling the Truth的更多相关文章

  1. 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 ( ...

  2. hdu 3729 I'm Telling the Truth 二分图匹配

    裸的二分图匹配.需要输出方案. #include<cstdio> #include<cstring> #include<vector> #include<al ...

  3. HDU 3729 I'm Telling the Truth (二分匹配)

    题意:给定 n 个人成绩排名区间,然后问你最多有多少人成绩是真实的. 析:真是没想到二分匹配,....后来看到,一下子就明白了,原来是水题,二分匹配,只要把每个人和他对应的区间连起来就好,跑一次二分匹 ...

  4. HDU - 3729 I'm Telling the Truth(二分匹配)

    题意:有n个人,每个人给出自己的名次区间,问最多有多少个人没撒谎,如果有多解,输出字典序最大的解. 分析: 1.因为字典序最大,所以从后往前分析. 2.假设后面的人没说谎,并将此作为已知条件,然后从后 ...

  5. hdu3729 I'm Telling the Truth (二分图的最大匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS (Java/ ...

  6. HDU 3729 I&#39;m Telling the Truth(二部图最大匹配+结果输出)

    职务地址:HDU 3729 二分图最大匹配+按字典序输出结果. 仅仅要从数字大的開始匹配就能够保证字典序最大了.群里有人问. . 就顺手写了这题. . 代码例如以下: #include <ios ...

  7. hdu 3729(二分图最大匹配)

    I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. UVALive 5033 I'm Telling the Truth 二分图最大匹配(略有修改)

    I - I'm Telling the Truth Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu ...

  9. HDU 2389 Rain on your Parade / HUST 1164 4 Rain on your Parade(二分图的最大匹配)

    HDU 2389 Rain on your Parade / HUST 1164 4 Rain on your Parade(二分图的最大匹配) Description You're giving a ...

  10. HDU 2444 The Accomodation of Students 二分图判定+最大匹配

    题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...

随机推荐

  1. HTML5 离线缓存

    离线资源缓存  为了能够让用户在离线状态下继续访问 Web 应用,开发者需要提供一个 cache manifest 文件.这个文件中列出了所有需要在离线状态下使用的资源,浏览器会把这些资源缓存到本地. ...

  2. (转)如何将ecshop首页主广告位的flash轮播替换为js轮播

    转之--http://www.ecshoptemplate.com/article-1710.html 这个ecshop很常见,因为现在比起flash难以修改,js更加符合人们的使用习惯,而默认ecs ...

  3. Css简介

  4. C# Double String互转

    /// <summary> /// str转金额 元 /// </summary> /// <param name="money"></p ...

  5. ExtJs API 下载以及部署

    ExtJs API 下载方法 1.进入sencha官网:https://www.sencha.com/ 2.点击“Docs”进入文档帮助页面:http://docs.sencha.com/ 3.点击左 ...

  6. Delphi 串口通信(1)

    利用 Delphi实现串口通信的常用的方法有 3种: 一是利用控件,如 MSCOMM控件和 SPCOMM控件: 二是使用 API函数: 三是调用其他串口通信程序.其中利用 API编写串口通信程序较为复 ...

  7. php中session的运行机制

    在PHP中session默认是以文件的形式存储于服务器的 而客户端和服务端则是通过session_id来完成握手的,默认情况下PHP会将session_id存储于cookie中,用户每次请求时该ses ...

  8. 《asp.net mvc3 高级编程》第三章 视图

    一.视图的作用 视图的职责是向用户提供界面.从ASP.NET MVC3开始,视图数据也可以通过ViewBag属性访问.例如:ViewBag.Message 就等于ViewData["Mess ...

  9. TCP\UDP链接的异同

    简单的说TCP与UDP的区别是有无连接状态.TCP是有连接状态的,而UDP没有,所以TCP是一种比较安全的通讯协议,而UDP则比较方便 TCP 127.0.0.1:1026 0.0.0.0:0 LIS ...

  10. 利用WebApi获取手机号码归属地

    前述: 在WebApi中,涉及到一个重要的类,HttpWebRequest. 学习link:httpwebrequest详解 示例演示: 代码示例: 1.前端代码: @{ ViewBag.Title ...