题目链接: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. 函数xdes_set_bit

    /**********************************************************************//** Sets a descriptor bit of ...

  2. MySql和Hibernate中关于cascade的用法

    数据库里的cascade的用法,Mysql和Hibernate里面是不相同. 在数据库里,进行增加.修改.删除记录的时候,经常会涉及到父子关系的表. 例如:有省份表和城市表,其中城市表有一个外键pro ...

  3. BZOJ1048: [HAOI2007]分割矩阵

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1048 题解:搞清题意之后来个记忆化爆搜就行了. 代码: #include<cstdio& ...

  4. OK335xS psplash 进度条工作原理 hacking

    #!/bin/sh # # rc This file is responsible for starting/stopping # services when the runlevel changes ...

  5. Content-Type

    HTTP Content-type .*( 二进制流,不知道下载文件类型) application/octet-stream .txt text/plain 没有csv这种类型

  6. 【再见RMQ】NYOJ-119-士兵杀敌(三),区间内大小差值

    [题目链接:NYOJ-119] 思路:转自 点我 ,讲的挺好. #include <cstdio> #include <math.h> #define max(a,b) ((a ...

  7. TCP/IP详解学习笔记(1)-基本概念

    为什么会有TCP/IP协议 在世界上各地,各种各样的电脑运行着各自不同的操作系统为大家服务,这些电脑在表达同一种信息的时候所使用的方法是千差万别.就好像圣经中上帝打乱了各地人的口音,让他们无法合作一样 ...

  8. oracle 统计语句 与常见函数的归纳(未完待续)

    一.统计语句 1. count count(*)与count(0)语句的区别: count(*)统计所有数量 count(0)统计第一列不为空的 2. 两个统计量的减法 select (select ...

  9. 类装载器ClassLoader

    类装载器工作机制 类装载器就是寻找类的节码文件并构造出类在JVM内部表示对象的组件.在Java中,类装载器把一个类装入JVM中,要经过以下步骤: [1.]装载:查找和导入Class文件: [2.]链接 ...

  10. 《C++ primer》--第10章

    习题10.21 解释map和set容器的差别,以及他们各自适用的情况. 解答: map容器和set容器的差别在于: map容器是键-值对的集合,而set容器只是键的集合: map类型适用于需要了解键与 ...