题目链接: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. JEE学习线路

    传智播客:javaEE学习线路以及需要掌握的知识点:http://java.itcast.cn/subject/javastudypath/index.shtml 最近在学JavaEE,没学Java ...

  2. 1934. Black Spot(spfa)

    1934 水题 RE了N久 后来发现是无向图 #include <iostream> #include<cstring> #include<algorithm> # ...

  3. adb shell settings ....

    Android4.2的源码android-17\com\android\commands目录下较之前的版本多了一个settings命令,查看其中的SettingsCmd.java文件,末尾有命令的帮助 ...

  4. UVa 120 Stacks of Flapjacks【构造法】

    题意:给出n张煎饼,从上到下输入,每张煎饼上面都有一个数字,厨师每次可以选择第k张煎饼,进行翻转操作,设计一种方法使得所有煎饼按照从小到大排序(最上面的煎饼最小) 首先是这个翻转的操作,如下图 如图所 ...

  5. python模拟http请求

    下文主要讲述如何利用python自带的库模拟http请求,为以后利用python做API测试做准备. 只讲述模拟http的过程,具体到自己用的时候,要以自己的应用为准做出适当的调整. #!coding ...

  6. Java [Leetcode 328]Odd Even Linked List

    题目描述: Given a singly linked list, group all odd nodes together followed by the even nodes. Please no ...

  7. VirtualBox的工作原理&参考网上文章

    事先申明,我这里有好多东西都是看网上的,文末给出参考博客链接. 1.在设置里面为什么要选择桥接网络?baidu之后,了解到是虚拟机工作原理的不同,也就是说有好几种工作模式. bridged(桥接模式) ...

  8. noip2007提高组题解

    题外话:这一年的noip应该是最受大众关心的,以至于在百度上输入noip第三个关键字就是noip2007.主要是由于这篇文章:http://www.zhihu.com/question/2110727 ...

  9. 【转】堆栈跟踪中收到一个UnhandledExceptionFilter调用时,如何查找问题异常堆栈

    定义没有异常处理程序来处理引发的异常时调用UnhandledExceptionFilter函数.函数通常将异常传递到捕获并处理它所尝试的 Ntdll.dll 文件. 在某些情况下,在其中存在的进程内存 ...

  10. ADO.NET访问SQL Server调用存储过程带回参

    1,ADO.NET访问SQL Server调用存储过程带回参 2,DatabaseDesign  use northwind go --存储过程1 --插入一条商品 productname=芹菜 un ...