题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1997

这个星球上有两种人,一种进酒吧至少玩a小时,另一种进酒吧最多玩b小时。

下面n行是人进进出出的时刻,0为进,1为出。让你求是否有合法解。

将合法的进入和出去连边,然后二分匹配就可以了。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e3 + ;
struct data {
int a , b;
bool operator <(const data &cmp) const {
return a < cmp.a;
}
}xx[N];
vector <int> G[N];
vector <int> vc;
int match[N];
bool vis[N]; bool dfs(int u) {
for(int i = ; i < G[u].size() ; ++i) {
int v = G[u][i];
if(!vis[v]) {
vis[v] = true;
if(match[v] == - || dfs(match[v])) {
match[v] = u;
match[u] = v;
return true;
}
}
}
return false;
} bool hungry() {
int res = ;
for(int i = ; i < vc.size() ; ++i) {
memset(vis , false , sizeof(vis));
if(dfs(vc[i]))
res++;
}
if(vc.size() == res)
return true;
return false;
} void solve() {
memset(match , - , sizeof(match));
if(hungry()) {
printf("No reason\n");
for(int i = ; i < vc.size() ; ++i) {
printf("%d %d\n" , xx[match[vc[i]]].a , xx[vc[i]].a);
}
}
else {
printf("Liar\n");
}
} int main()
{
int x , y , n;
while(~scanf("%d %d" , &x , &y)) {
scanf("%d" , &n);
int index = ;
for(int i = ; i <= n ; ++i) {
scanf("%d %d" , &xx[i].a , &xx[i].b);
}
sort(xx + , xx + n + );
for(int i = ; i <= n ; ++i) {
if(xx[i].b) {
vc.push_back(i);
for(int j = ; j < i ; ++j) {
if(!xx[j].b && (xx[i].a - xx[j].a <= y || xx[i].a - xx[j].a >= x))
G[i].push_back(j);
}
}
}
solve();
}
return ;
}

Timus OJ 1997 Those are not the droids you're looking for (二分匹配)的更多相关文章

  1. URAL-1997 Those are not the droids you're looking for 二分匹配

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1997 题意:记录了n个人进出门的时间点,每个人在房子里面待的时间要么小于等于a,要么大于 ...

  2. Just Oj 2017C语言程序设计竞赛高级组E: DATE ALIVE(二分匹配)

    E: DATE ALIVE 时间限制: 1 s      内存限制: 128 MB 提交 我的状态 题目描述 五河士道家里的精灵越来越多了,而每一个精灵都想和他有一个约会.然而五河士道却只有一个,无奈 ...

  3. URAL 1997 Those are not the droids you're looking for 二分图最大匹配

    Those are not the droids you're looking for 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1 ...

  4. URAL 1997 Those are not the droids you're looking for

    二分图的最大匹配. 每一个$0$与$1$配对,只建立满足时差大于等于$a$或者小于等于$b$的边,如果二分图最大匹配等于$n/2$,那么有解,遍历每一条边输出答案,否则无解. #include< ...

  5. Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集

    m种阳离子 n种阴离子 然后一个m*n的矩阵 第i行第j列为1代表第i种阴离子和第j种阴离子相互吸引 0表示排斥 求在阳离子和阴离子都至少有一种的情况下 最多存在多少种离子能够共存 阴阳离子都至少须要 ...

  6. light oj 1149 Factors and Multiples(二分匹配)

    LightOJ1149 :Factors and Multiples 时间限制:2000MS    内存限制:32768KByte   64位IO格式:%lld & %llu 描述 You w ...

  7. OJ大集合、

    转载自:传送门 什么是OJ Online Judge系统(简称OJ)是一个在线的判题系统.用户可以在线提交程序源代码,系统对源代码进行编译和执行,并通过预先设计的测试数据来检验程序源代码的正确性. 一 ...

  8. OnlineJudge大集合

    什么是OJ Online Judge系统(简称OJ)是一个在线的判题系统.用户可以在线提交程序源代码,系统对源代码进行编译和执行,并通过预先设计的测试数据来检验程序源代码的正确性. 一个用户提交的程序 ...

  9. 转债---Pregel: A System for Large-Scale Graph Processing(译)

    转载:http://duanple.blog.163.com/blog/static/70971767201281610126277/   作者:Grzegorz Malewicz, Matthew ...

随机推荐

  1. Building Xcode iOS projects and creating *.ipa file from the command line

    For our development process of iOS applications, we are using Jenkins set up on the Mac Mini Server, ...

  2. Topcoder SRM 630 (500 floyed 暴力 _builtin_popcount())

    题意:给n个点,保证图联通,给点相连的距离,求一个最多的点,这些点之间的距离都是相同的. 分析: 下面的代码是我们房间第一的大神的,写的很简洁,我的思路和他的一样,但是我不知道错哪了. 思路是暴力枚举 ...

  3. uva 111 - History Grading (dp, LCS)

    题目链接 题意:给N,第二行是答案,n个数c1---cn, 代表第一个的顺序是c1,第二个数顺序是c2; 下面每一行是学生的答案,格式同上. 注意:这个给的顺序需要处理一下,不能直接用. 思路:LCS ...

  4. Android_PendingIntent的使用

        PendingIntent介绍 PendingIntent可以看作是对Intent的一个封装,但它不是立刻执行某个行为,而是满足某些条件或触发某些事件后才执行指定的行为. PendingInt ...

  5. freemarker中判断对象是否为空

    <#if xxx?exists> 或则 <#if xxx??>两个问号??最简单方便

  6. Linux shell下批量创建缩略图

    一.背景 今天,突然发现手机客户端上的最新新闻缩略图都不显示了,上服务器上看了看, 发现新的新闻图片根本没有生成缩略图. 这套新闻发布系统是很老的程序了,查了一下,问题的原因是不支持png格式的图片, ...

  7. ti processor sdk linux am335x evm setup.sh hacking

    #!/bin/sh # # ti processor sdk linux am335x evm setup.sh hacking # 说明: # 本文主要对TI的sdk中的setup.sh脚本进行解读 ...

  8. Linux busybox mount -a fstab

    /*********************************************************************** * Linux busybox mount -a fs ...

  9. highcharts 柱状图动态设置数据应用实例

    <div id="container" style="min-width:700px;height:400px"></div> #jav ...

  10. 【C#学习笔记】打开新进程

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...