POJ 3683 Priest John's Busiest Day (2-SAT)
题意:有n对新人要在同一天结婚。结婚时间为Ti到Di,这里有时长为Si的一个仪式需要神父出席。神父可以在Ti-(Ti+Si)这段时间出席也可以在(Di-Si)-Si这段时间。问神父能否出席所有仪式,如果可以输出一组时间安排。
思路:2-SAT。神父可以在开始出席也可以在结束时候出席,要求与其他出席时间没有冲突,这样建图计算即可。另一一定要弄清楚true和false代表的含义。
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
;
struct TwoSAT
{
int n;
vector<];
];
],c;
bool dfs(int x)
{
]) return false;
if(mark[x]) return true;
mark[x]=true;
S[c++]=x;
; i<G[x].size(); ++i)
if(!dfs(G[x][i])) return false;
return true;
}
void init(int n)
{
this->n=n;
; i<n*; ++i) G[i].clear();
memset(mark,,sizeof(mark));
}
void add_clause(int x,int xval,int y,int yval)
{
x=x*+xval;
y=y*+yval;
G[x^].push_back(y);
G[y^].push_back(x);
}
bool solve()
{
; i<n*; i+=)
{
])
{
c=;
if(!dfs(i))
{
) mark[S[--c]]=false;
)) return false;
}
}
}
return true;
}
};
TwoSAT solver;
bool judge(int st1,int ed1,int st2,int ed2)
{
if(st1<=st2&&ed2<=ed1) return true;
if(st2<=st1&&ed1<=ed2) return true;
if(st1<st2&&st2<ed1&&ed2>ed1) return true;
if(st2<st1&&st1<ed2&&ed1>ed2) return true;
return false;
}
int TimetoInt(string str)
{
]-+(str[]-+(str[]-+(str[]-');
return t;
}
string InttoTime(int t)
{
string str;
,b=t%;
str+=(a/+');
str+=(a%+');
str+=':';
str+=(b/+');
str+=(b%+');
return str;
}
],t[][];
int n;
bool solve()
{
solver.init(n);
; i<n; ++i); a<; ++a)
; j<n; ++j) ; b<; ++b)
{
int ast,aed;
int bst,bed;
) ast=t[i][a],aed=t[i][a]+cost[i];
else ast=t[i][a]-cost[i],aed=t[i][a];
)bst=t[j][b],bed=t[j][b]+cost[j];
else bst=t[j][b]-cost[j],bed=t[j][b];
if(judge(ast,aed,bst,bed))
solver.add_clause(i,a^,j,b^);
}
return solver.solve();
}
int main()
{
while(cin>>n)
{
; i<n; ++i)
{
string st,ed;
cin>>st>>ed>>cost[i];
t[i][]=TimetoInt(st);
t[i][]=TimetoInt(ed);
}
if(!solve()) cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
; i<*n; i+=)
{
if(!solver.mark[i])
cout<<InttoTime(t[i/][])<<][]+cost[i/])<<endl;
else
cout<<InttoTime(t[i/][]-cost[i/])<<][])<<endl;
}
}
}
;
}
POJ 3683 Priest John's Busiest Day (2-SAT)的更多相关文章
- POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 Priest John's Busiest Day(2-sat问题)
POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 Priest John's Busiest Day(2-sat问题) Descripti ...
- POJ 3683 Priest John's Busiest Day(2-SAT+方案输出)
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10010 Accep ...
- POJ 3683 Priest John's Busiest Day (2-SAT)
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6900 Accept ...
- POJ 3683 Priest John's Busiest Day(2-SAT 并输出解)
Description John is the only priest in his town. September 1st is the John's busiest day in a year b ...
- poj - 3683 - Priest John's Busiest Day(2-SAT)
题意:有N场婚礼,每场婚礼的开始时间为Si,结束时间为Ti,每场婚礼有个仪式,历时Di,这个仪式要么在Si时刻开始,要么在Ti-Di时刻开始,问能否安排每场婚礼举行仪式的时间,使主持人John能参加所 ...
- POJ 3683 Priest John's Busiest Day (2-SAT,常规)
题意: 一些人要在同一天进行婚礼,但是牧师只有1个,每一对夫妻都有一个时间范围[s , e]可供牧师选择,且起码要m分钟才主持完毕,但是要么就在 s 就开始,要么就主持到刚好 e 结束.因为人数太多了 ...
- POJ 3683 Priest John's Busiest Day
2-SAT简单题,判断一下两个开区间是否相交 #include<cstdio> #include<cstring> #include<cmath> #include ...
- POJ 3683 Priest John's Busiest Day[2-SAT 构造解]
题意: $n$对$couple$举行仪式,有两个时间段可以选择,问是否可以不冲突举行完,并求方案 两个时间段选择对应一真一假,对于有时间段冲突冲突的两人按照$2-SAT$的规则连边(把不冲突的时间段连 ...
- POJ 3683 Priest John's Busiest Day 【2-Sat】
这是一道裸的2-Sat,只要考虑矛盾条件的判断就好了. 矛盾判断: 对于婚礼现场 x 和 y,x 的第一段可以和 y 的第一段或者第二段矛盾,同理,x 的第二段可以和 y 的第一段或者第二段矛盾,条件 ...
随机推荐
- linux学习网站分享
http://www.zhihu.com/question/19895288 http://linux.vbird.org/ 两个linux学习的网页存起来,以后学习.
- java/Android 接口调用的几种写法
虽然Handler用的地方比较普遍,但是接口也有他的独特之处,比较直观,然后降低了耦合性 如有一接口,需要将数据传给使用的activity中,接口如下 public interface PushVal ...
- AxureRP8实战手册(基础21-30)
AxureRP8实战手册(基础21-30) 本文目录 基础21. 设置元件默认选中/禁用 基础22. 设置单选按钮唯一选中 基础23. 设置元件不同状态时的样式 基础24. ...
- TableView与delegate、dataResource
小梦这几天学习tableView是深有体会了 废话不多说,来一波 首先,创建一个测试项目 如图 创建好,在项目结构中另外弄一个GroupFile,创建storyBoard和CocoaTouch 在st ...
- IntelliJ IDEA 2016
IntelliJ IDEA 2016 注册码 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1Ii ...
- 利用mysql_multi来管理多实例:
mysql_multi的现实意义: 1:随着连接数上升,性能会下降,通过多实例来分流大量连接来提高性能. 2:做资源隔离 3:分库分表 mysql_multi是官方管理多实例的一个脚本,利用perl语 ...
- guava学习--Objects
转载:https://my.oschina.net/realfighter/blog/349821 Java中的Object类是所有Java类的超类(也就是祖先),所有对象都实现Object类中的方法 ...
- ORACLE中的支持正则表达式的函数
ORACLE中的支持正则表达式的函数主要有下面四个:1,REGEXP_LIKE :与LIKE的功能相似2,REGEXP_INSTR :与INSTR的功能相似3,REGEXP_SUBSTR :与SUBS ...
- 使用centos引导内核错误:kernel: pnp 00:0b: can't evaluate _CRS: 8
CentOS系统在开机过程中,一直遇到黑屏提示:“kernel: pnp 00:0b: can't evaluate _CRS: 8”,不理会它仍能启动系统并正常工作,未知何故. 经查,这是内核引导的 ...
- 关于HTML5、Jquery、Phonegap跨域问题的研究
我的问题: 近期研究Phonegap的相关技术,遇到了服务资源访问的跨域.经过尝试使用服务器端的代理,Phonegap打包后不能够访问到相应资源.在搜索引擎的帮助下,找到了Jquery的jsonp的方 ...