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 的第一段或者第二段矛盾,条件 ...
随机推荐
- 《高级Web应用程序设计》课程
一.课堂课件 全部授课内容 二.作业 访问ftp://192.168.42.254:22,登录后找到自己的姓名文件夹,放入作业即可.登录账号为stu1,密码为空. 已布置练习 练习1(截止日期10月1 ...
- express+gulp构建项目(五)swig模板
这里的文件负责配置swig模板引擎. index.js var jsonHash = require('./json_file'); var staticTag = require("./t ...
- ArcGIS发布服务时缓存切片设置
[文件]>[共享]>[服务]>[覆盖原有服务]或[创建新服务] 设置好相关参数后,会弹出"服务编辑框": 进入"缓存" 1."绘制此 ...
- BADI_MATERIAL_CHECK(物料主数据表的增强检查)
多次调用的BADI,'业务加载项定义的多重使用意味着可以有多个活动的 业务加载项实施.在进行调用时,将调用所有上述实施,但调用顺序不可预期. 因此,如果使用多重使用 业务加载项定义,那么顺序不得起到任 ...
- 解决VS2015安装Android SDK 后文件不全及更新问题
近日安装VS2015专业版后.想进行Android开发,就新建了一个Blank app 结果报[值不能为空 null 参数名:path1] 1:首先检查工具 xamarin 工具那设置的SDK路径对不 ...
- 把word文档中的所有图片导出
把word文档中的所有图片导出 end
- JavaEE Hibernate初级概念
1. Hibernate 是连接Java应用程序和关系数据库的中间件: 对JDBC API进行了封装.负责Java对象的持久化: 在三层软件架构中它位于持久层(数据访问层),封装了所有数据访问细节, ...
- 在MyEclipse中配置Tomcat服务器
http://wenku.baidu.com/link?url=j0rrOEvt10zgsJVWX3wuV26uVc2fz5MhIusvLWzvK_KZWMKq60wuDaMnHGck0PR6sCrU ...
- 1627. Join
http://acm.timus.ru/problem.aspx?space=1&num=1627 给一个无向图,问可以有多少生成树 参照 周冬<生成树的计数及其应用> 代 ...
- 【 2013 Multi-University Training Contest 3 】
HDU 4622 Reincarnation 枚举字符串的起点,构造后缀自动机,每次插入一个字符,就能统计得到当前不同字串的个数,预处理出所有的询问. #include<cstdio> # ...