URAL-1997 Those are not the droids you're looking for 二分匹配
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1997
题意:记录了n个人进出门的时间点,每个人在房子里面待的时间要么小于等于a,要么大于等于b,询问能否对进出门的时间点找到一个合适的匹配。
对于满足的要求建立边即可,然后看是否能找到最大匹配。
//STATUS:C++_AC_109MS_4361KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int vis[N],y[N],w[N][N],t[N][],id[N],l[N],r[N];
int n,a,b,cnt1,cnt2; int dfs(int u)
{
int v;
for(v=;v<cnt1;v++){
if(vis[v] || !w[u][v])continue;
vis[v]=;
if(y[v]==- || dfs(y[v])){
y[v]=u;
return ;
}
}
return ;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,L,R,ok;
while(~scanf("%d%d",&a,&b))
{
L=b+,R=a-;
scanf("%d",&n);
cnt1=cnt2=;
for(i=;i<n;i++){
scanf("%d%d",&t[i][],&t[i][]);
if(t[i][]){
l[cnt1]=i;
id[i]=cnt1++;
}
else {
r[cnt2]=i;
id[i]=cnt2++;
}
}
mem(w,);
for(i=;i<n;i++){
if(t[i][]==)continue;
for(j=i-;j>=;j--){
if(t[j][]==)continue;
if(t[i][]-t[j][]>=L && t[i][]-t[j][]<=R)continue;
w[id[i]][id[j]]=;
}
}
mem(y,-);ok=;
for(i=;i<cnt1;i++){
mem(vis,);
if(dfs(i)==){
ok=;
break;
}
} if(ok){
printf("No reason\n");
for(i=;i<cnt1;i++){
printf("%d %d\n",t[r[i]][],t[ l[ y[i] ] ][]);
}
}
else printf("Liar\n"); }
return ;
}
URAL-1997 Those are not the droids you're looking for 二分匹配的更多相关文章
- 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行是 ...
- 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< ...
- 转债---Pregel: A System for Large-Scale Graph Processing(译)
转载:http://duanple.blog.163.com/blog/static/70971767201281610126277/ 作者:Grzegorz Malewicz, Matthew ...
- 二分图水一波~~~~d带你飞
Current Time: 2016-03-11 17:45:36 Contest Type: Public Start Time: 2016-03-04 13:00:00 Contest Statu ...
- [kuangbin带你飞]专题十 匹配问题
A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找 ID Origin Title 61 / 72 Problem A HD ...
- Pregel: A System for Large-Scale Graph Processing(译)
[说明:Pregel这篇是发表在2010年的SIGMOD上,Pregel这个名称是为了纪念欧拉,在他提出的格尼斯堡七桥问题中,那些桥所在的河就叫Pregel.最初是为了解决PageRank计算问题,由 ...
- HDU分类
原地址:http://www.byywee.com/page/M0/S607/607452.html 总结了一下ACM STEPS的各章内容,趁便附上我的Steps题号(每人的不一样). 别的,此文首 ...
- [二分匹配]URAL1721Two Sides of the Same Coin
题意:给n个人,每个人都有3个参数,分别是名字,能做的事(a:statements b:testdate a.b都可以:anything),Rank 要求:一个人只能做一个事件,要两个人Rank相 ...
随机推荐
- POJ 3494 Largest Submatrix of All 1’s(最大全1子矩阵)
题目链接:http://poj.org/problem?id=3494 题意:给出一个01的矩阵,找出一个面积最大的全1矩阵. 思路:用h[i][j]表示从位置(i,j)向上连续1的最大长度.之后枚举 ...
- C#中的转换
11.3 转换 到目前为止,在需要把一种类型转换为另一种类型时,使用的都是类型转换.而这并不是唯一的方式. 在计算过程中,int可以采用相同的方式隐式转换为long或double,还可以定义所创建的 ...
- [HIHO1223]不等式(离散化,枚举)
题目链接:http://hihocoder.com/problemset/problem/1223 这题不难,难点在于小数的处理.可以0.5为步长枚举,也可以扩大偶数倍枚举. /* ━━━━━┒ギリギ ...
- ogre世界坐标鱼屏幕坐标相互转换
bool worldCoordToScreen(Vector3 objPos, Camera* cam, Vector2 screenRect, Vector2& screenPos) { ...
- jQuery_效果(淡入淡出)
1.jQuery fadeIn() 方法( 用于淡入已隐藏的元素.) 语法: $(selector).fadeIn(speed,callback); 可选的 speed 参数规定效果的时长.它可以取以 ...
- Hack 【二分答案】
题意:给出n门课程,每一门课程考的分数,每一门课程的学分,求最多删去k组数据之后能够得到的最大加权平均数 先开一个数组x[],其中x[i]=1代表没有删除这门课程,x[i]=0表示删除了这门课程 然后 ...
- Ref相关的名词解释
NV (NOT-VOLATILE),即非易失性,断电不会丢失的存储信息,包括生产信息.客户信息.产品信息等等. 它们都保存在不同(FLASH)分区,并根据不同的分区提供不同的接口.数据结构和管理机制. ...
- LeetCode Valid Number 有效数字(有限自动机)
题意:判断一个字符串是否是一个合法的数字,包括正负浮点数和整形. 思路:有限自动机可以做,画个图再写程序就可以解决啦,只是实现起来代码的长短而已. 下面取巧来解决,分情况讨论: (1)整数 (2)浮点 ...
- php 换行 PHP_EOL变量
一个小小的换行,其实在不同的平台有着不同的实现,为什么要这样,可以是世界是多样的. 本来在unix世界换行就用/n来代替,但是windows为了体现他的不同,就用/r/n,更有意思的是在mac中用/r ...
- 【C#学习笔记】文本复制到粘贴板
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...