Timus OJ 1997 Those are not the droids you're looking for (二分匹配)
题目链接: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 (二分匹配)的更多相关文章
- URAL-1997 Those are not the droids you're looking for 二分匹配
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1997 题意:记录了n个人进出门的时间点,每个人在房子里面待的时间要么小于等于a,要么大于 ...
- Just Oj 2017C语言程序设计竞赛高级组E: DATE ALIVE(二分匹配)
E: DATE ALIVE 时间限制: 1 s 内存限制: 128 MB 提交 我的状态 题目描述 五河士道家里的精灵越来越多了,而每一个精灵都想和他有一个约会.然而五河士道却只有一个,无奈 ...
- 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 ...
- URAL 1997 Those are not the droids you're looking for
二分图的最大匹配. 每一个$0$与$1$配对,只建立满足时差大于等于$a$或者小于等于$b$的边,如果二分图最大匹配等于$n/2$,那么有解,遍历每一条边输出答案,否则无解. #include< ...
- Light OJ 1373 Strongly Connected Chemicals 二分匹配最大独立集
m种阳离子 n种阴离子 然后一个m*n的矩阵 第i行第j列为1代表第i种阴离子和第j种阴离子相互吸引 0表示排斥 求在阳离子和阴离子都至少有一种的情况下 最多存在多少种离子能够共存 阴阳离子都至少须要 ...
- light oj 1149 Factors and Multiples(二分匹配)
LightOJ1149 :Factors and Multiples 时间限制:2000MS 内存限制:32768KByte 64位IO格式:%lld & %llu 描述 You w ...
- OJ大集合、
转载自:传送门 什么是OJ Online Judge系统(简称OJ)是一个在线的判题系统.用户可以在线提交程序源代码,系统对源代码进行编译和执行,并通过预先设计的测试数据来检验程序源代码的正确性. 一 ...
- OnlineJudge大集合
什么是OJ Online Judge系统(简称OJ)是一个在线的判题系统.用户可以在线提交程序源代码,系统对源代码进行编译和执行,并通过预先设计的测试数据来检验程序源代码的正确性. 一个用户提交的程序 ...
- 转债---Pregel: A System for Large-Scale Graph Processing(译)
转载:http://duanple.blog.163.com/blog/static/70971767201281610126277/ 作者:Grzegorz Malewicz, Matthew ...
随机推荐
- ie6调试工具Debugbar
http://www.my-debugbar.com/wiki/Doc/DebugbarInstall
- 1033. Labyrinth(dfs)
1033 简单dfs 有一点小小的坑 就是图可能不连通 所以要从左上和右下都搜一下 加起来 从讨论里看到的 讨论里看到一句好无奈的回复 “可不可以用中文呀...” #include <iostr ...
- WIN7开无线
可以的,WIN7自身就带有这个功能的,不过默认是不开启的,也可以下载一个软件来弄.1.请却仍您使用的操作系统是微软的Windows 7或者Windows server 2008 R2,正版盗版皆可.( ...
- iphone 如何清空UIWebView的缓存
iphonecachingapplicationcookiescacheperformance I actually think it may retain cached information ...
- test chemes
rcmobile://messages rcmobile://badge rcmobile://dialer rcmobile://open rcmobile://sms?type=new
- MVC&WebForm对照学习:文件下载
说完了WebForm和MVC中的文件上传,就不得不说用户从服务器端下载资源了.那么今天就扯扯在WebForm和MVC中是如何实现文件下载的.说起WebForm中的文件上传,codeshark在他的博文 ...
- 【ASP.NET】编程点滴 :ASP.NET身份验证
ASP.NET实际开发中身份验证 是一个不可回避的问题.在相当一段长的时间内,由于不求甚解,我对这个话题似懂非懂.今天就对它做个简单的小结. Authentication and Authorizat ...
- ZOJ1311, POJ1144 Network
题目描述:TLC电话线路公司正在新建一个电话线路网络.他们将一些地方(这些地方用1到N的整数标明,任何2个地方的标号都不相同)用电话线路连接起来.这些线路是双向的,每条线路连接2个地方,并且每个地方的 ...
- [Everyday Mathematics]20150104
设 $a>0$, $$\bex x_1=1,\quad x_{n+1}=x_n+an\prod_{i=1}^n x_i^{-\frac{1}{n}}. \eex$$ 试证: $$\bex \vl ...
- 深度学习String、StringBuffer、StringBuilder
相信String这个类是Java中使用得最频繁的类之一,并且又是各大公司面试喜欢问到的地方,今天就来和大家一起学习一下String.StringBuilder和StringBuffer这几个类,分析它 ...