题意:

$n$对$couple$举行仪式,有两个时间段可以选择,问是否可以不冲突举行完,并求方案


两个时间段选择对应一真一假,对于有时间段冲突冲突的两人按照$2-SAT$的规则连边(把不冲突的时间段连起来)

然后本题需要构造解,所以要$SCC$缩点反向建图记录否定再拓扑排序$dfs$染色,好麻烦...

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=,M=1e6+;
typedef long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,m;
struct person{
int a,b;
}p[N];
struct edge{
int v,ne;
}e[M],e2[M];
int h[N],h2[N],cnt=;
inline void ins(int u,int v){
cnt++;
e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
}
inline void ins2(int u,int v){
cnt++;
e2[cnt].v=v;e2[cnt].ne=h2[u];h2[u]=cnt;
}
inline bool isIn(int x,int y){
if(p[x].b<=p[y].a||p[x].a>=p[y].b) return false;
return true;
}
void buildGraph(){
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++){
int x=i<<,y=j<<;
if(isIn(x-,y-)) ins(x-,y),ins(y-,x);
if(isIn(x-,y)) ins(x-,y-),ins(y,x);
if(isIn(x,y-)) ins(x,y),ins(y-,x-);
if(isIn(x,y)) ins(x,y-),ins(y,x-);
}
}
int dfn[N],low[N],dfc,belong[N],scc;
int st[N],top;
void dfs(int u){
dfn[u]=low[u]=++dfc;
st[++top]=u;
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v;
if(!dfn[v]){
dfs(v);
low[u]=min(low[u],low[v]);
}else if(!belong[v])
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
scc++;
while(true){
int x=st[top--];
belong[x]=scc;
if(x==u) break;
}
}
}
bool judge(){
for(int i=;i<=n;i++) if(belong[i<<]==belong[(i<<)-]) return false;
return true;
}
int ind[N];
void rebuildGraph(){
int _=n<<;
cnt=;
for(int u=;u<=_;u++)
for(int i=h[u];i;i=e[i].ne)
if(belong[u]!=belong[e[i].v])
ins2(belong[e[i].v],belong[u]),ind[belong[u]]++;
}
int color[N];
void dfsCol(int u){
if(color[u]) return;
color[u]=;
for(int i=h2[u];i;i=e2[i].ne) dfsCol(e2[i].v);
}
int opp[N];
void topoSort(){
top=;
for(int i=;i<=scc;i++) if(!ind[i]) st[++top]=i;
while(top){
int u=st[top--];
if(color[u]) continue;
color[u]=;dfsCol(opp[u]);
for(int i=h2[u];i;i=e2[i].ne){
int v=e2[i].v;
ind[v]--;
if(!ind[v]) st[++top]=v;
}
}
}
void print(int a,int b){
printf("%.2d:%.2d ",a/,a%);
printf("%.2d:%.2d ",b/,b%);
puts("");
}
int main(){
freopen("in","r",stdin);
n=read();
for(int i=;i<=n;i++){
int x=i<<,t;
t=read();
p[x-].a=t*+read();
t=read();
p[x].b=t*+read();
t=read();
p[x-].b=p[x-].a+t;
p[x].a=p[x].b-t;
}
buildGraph();
int _=n<<;
for(int i=;i<=_;i++) if(!dfn[i]) dfs(i);
if(!judge()) puts("NO");
else{
puts("YES");
rebuildGraph();
for(int i=;i<=n;i++){
int x=i<<;
opp[belong[x]]=belong[x-];
opp[belong[x-]]=belong[x];
}
topoSort();
for(int i=;i<=n;i++){
int x=i<<;
if(color[belong[x]]==) print(p[x].a,p[x].b);
else print(p[x-].a,p[x-].b);
}
}
}

POJ 3683 Priest John's Busiest Day[2-SAT 构造解]的更多相关文章

  1. 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 ...

  2. POJ 3683 Priest John's Busiest Day(2-SAT+方案输出)

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10010   Accep ...

  3. POJ 3683 Priest John's Busiest Day (2-SAT)

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6900   Accept ...

  4. 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 ...

  5. poj - 3683 - Priest John's Busiest Day(2-SAT)

    题意:有N场婚礼,每场婚礼的开始时间为Si,结束时间为Ti,每场婚礼有个仪式,历时Di,这个仪式要么在Si时刻开始,要么在Ti-Di时刻开始,问能否安排每场婚礼举行仪式的时间,使主持人John能参加所 ...

  6. POJ 3683 Priest John's Busiest Day (2-SAT)

    题意:有n对新人要在同一天结婚.结婚时间为Ti到Di,这里有时长为Si的一个仪式需要神父出席.神父可以在Ti-(Ti+Si)这段时间出席也可以在(Di-Si)-Si这段时间.问神父能否出席所有仪式,如 ...

  7. POJ 3683 Priest John's Busiest Day (2-SAT,常规)

    题意: 一些人要在同一天进行婚礼,但是牧师只有1个,每一对夫妻都有一个时间范围[s , e]可供牧师选择,且起码要m分钟才主持完毕,但是要么就在 s 就开始,要么就主持到刚好 e 结束.因为人数太多了 ...

  8. POJ 3683 Priest John's Busiest Day

    2-SAT简单题,判断一下两个开区间是否相交 #include<cstdio> #include<cstring> #include<cmath> #include ...

  9. POJ 3683 Priest John's Busiest Day 【2-Sat】

    这是一道裸的2-Sat,只要考虑矛盾条件的判断就好了. 矛盾判断: 对于婚礼现场 x 和 y,x 的第一段可以和 y 的第一段或者第二段矛盾,同理,x 的第二段可以和 y 的第一段或者第二段矛盾,条件 ...

随机推荐

  1. 最新版Sublime Text Build 3156 x64 的下载 + 注册码 + Install Package Control + 汉化教程

    一.Sublime Text  下载 神器 Sublime Text 最近开始更新到开发版本 Build 3156,本身英语不是太6,汉化党自然各种百度汉化教程,网上不是一堆绿色汉化包,就是让你下载汉 ...

  2. hbase安装版本

    Hbase的安装部署,依赖HDFS,Zookeeper-3.4.5,jDK1.7以上,Hadoop-2.5.0以上

  3. 【LeetCode】476. Number Complement (java实现)

    原题链接 https://leetcode.com/problems/number-complement/ 原题 Given a positive integer, output its comple ...

  4. oracle存储过程的创建和使用

    创建存储过程: 格式:create or replace procedure procedure_name(参数 参数类型) Is/as 变量1 变量1的类型: begin ----------业务逻 ...

  5. spring定时任务执行两次 项目重复初始化 项目启动两次

    tomcat/config/server.xml中Host标签Context节点的问题 项目里quartz定时器总是被执行2次,通过打印发现原来项目被加载了两次,所以项目下的Listener被重复加载 ...

  6. UWP: 通过命令行启动 UWP 应用

    最近在开发应用的过程中,我遇到了如标题所述的需求,其实主要是为了能够快捷启动应用,正像我们可以在"运行"对话框中可以输入一些可执行程序的名称后,就能够直接启动它:这样做,可以增加 ...

  7. 高级设置电脑系统windows7防火墙出错代码0×6D9原因与解决技巧

    高级设置windows防火墙能够更好的保护电脑系统安全,在电脑系统windows7设置过程中难免会遇到某些问题,有用户在安装MRGT后想要打开SNMP的161端口,但在打开高级安全windows防火墙 ...

  8. vue 开发2017年变化回顾及2018年展望

    vue.js 变化 从 github 的发布记录我们可以看到2017年 vue.js 的第一个发布为 v2.1.9,最后一个为 v2.5.13,主要发布小版本 2.2~2.5.这些发布提升了vue 与 ...

  9. Oracle创建、管理撤销表空间

    撤销管理模式: 用户通过设定撤销管理模式(undo mode)就可以灵活地选择使用手动撤销管理(manual undo management)或自动撤销管理(automatic undo manage ...

  10. poweshell批量删除某类型文件

    错误方法 rm *.o" -recurse 按照提示,rm(remove-item)是可以递归删除子文件夹的.但是这个方法确实无效.在他们的示例里面找到说明: --------------- ...