题意

n对夫妻要结婚,第i对夫妻结婚的婚礼持续时间为[Si, Ti],他们会举行一个仪式,仪式时间为Di,这个仪式只能举行在开头或者结尾举行,要么[Si, Si+Di],要么[Ti-Di, Ti],然而举行仪式的牧师只有一个,问牧师能否举行完所有仪式

按输入顺序输出方案

手动翻译

Sol

\(2-SAT\)输出一组可行解

这个很烦

\(Tarjan\)缩点成\(DAG\)后再拓扑排序+染色

只传递不选的标记

# include <iostream>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <math.h>
# include <algorithm>
# include <queue>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(2005);
const int __(2e6 + 5); IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} int n, first[_], head[_], cnt, num, s[_], t[_], d[_], cho[_];
int S[_], vis[_], dfn[_], low[_], Index, col[_], deg[_], oth[_];
struct Edge{
int to, next;
} edge[__], dag[__];
queue <int> Q; IL void Add(RG int u, RG int v){
edge[cnt] = (Edge){v, first[u]}, first[u] = cnt++;
} IL void Add_DAG(RG int u, RG int v){
dag[cnt] = (Edge){v, head[u]}, head[u] = cnt++, ++deg[v];
} IL void Tarjan(RG int u){
vis[u] = 1, dfn[u] = low[u] = ++Index, S[++S[0]] = u;
for(RG int e = first[u]; e != -1; e = edge[e].next){
RG int v = edge[e].to;
if(!dfn[v]) Tarjan(v), low[u] = min(low[u], low[v]);
else if(vis[v]) low[u] = min(low[u], dfn[v]);
}
if(dfn[u] != low[u]) return;
RG int v = S[S[0]--]; col[v] = ++num, vis[v] = 0;
while(v != u) v = S[S[0]--], col[v] = num, vis[v] = 0;
} IL void Dfs(RG int u){
if(cho[u] != -1) return;
cho[u] = 0;
for(RG int e = head[u]; e != -1; e = dag[e].next) Dfs(dag[e].to);
} IL int GetTime(){
return Input() * 60 + Input();
} IL void OutTime(RG int x){
printf("%.2d:%.2d ", x / 60, x % 60);
} IL int Cross(RG int l1, RG int r1, RG int l2, RG int r2){
if(l1 > l2) swap(l1, l2), swap(r1, r2);
return r1 > l2;
} int main(RG int argc, RG char* argv[]){
n = Input(), Fill(first, -1), Fill(head, -1), Fill(cho, -1);
for(RG int i = 1; i <= n; ++i)
s[i] = GetTime(), t[i] = GetTime(), d[i] = Input();
for(RG int i = 1; i < n; ++i)
for(RG int j = i + 1; j <= n; ++j){
if(Cross(s[i], s[i] + d[i], s[j], s[j] + d[j])) Add(i, j + n), Add(j, i + n);
if(Cross(s[i], s[i] + d[i], t[j] - d[j], t[j])) Add(i, j), Add(j + n, i + n);
if(Cross(t[i] - d[i], t[i], s[j], s[j] + d[j])) Add(i + n, j + n), Add(j, i);
if(Cross(t[i] - d[i], t[i], t[j] - d[j], t[j])) Add(i + n, j), Add(j + n, i);
}
RG int tmp = n << 1; cnt = 0;
for(RG int i = 1; i <= tmp; ++i) if(!dfn[i]) Tarjan(i);
for(RG int i = 1; i <= n; ++i){
if(col[i] == col[i + n]) return puts("NO"), 0;
oth[col[i]] = col[i + n], oth[col[i + n]] = col[i];
}
puts("YES");
for(RG int i = 1; i <= tmp; ++i)
for(RG int e = first[i]; e != -1; e = edge[e].next)
if(col[i] != col[edge[e].to]) Add_DAG(col[edge[e].to], col[i]);
for(RG int i = 1; i <= num; ++i) if(!deg[i]) Q.push(i);
while(!Q.empty()){
RG int u = Q.front(); Q.pop();
if(cho[u] != -1) continue;
cho[u] = 1, Dfs(oth[u]);
for(RG int e = head[u]; e != -1; e = dag[e].next)
if(!--deg[dag[e].to]) Q.push(dag[e].to);
}
for(RG int i = 1; i <= n; ++i){
if(cho[col[i]]) OutTime(s[i]), OutTime(s[i] + d[i]);
else OutTime(t[i] - d[i]), OutTime(t[i]);
puts("");
}
return 0;
}

Poj3683:Priest John's Busiest Day的更多相关文章

  1. 【POJ3683】Priest John's Busiest Day

    题目 John is the only priest in his town. September 1st is the John's busiest day in a year because th ...

  2. 图论(2-sat):Priest John's Busiest Day

    Priest John's Busiest Day   Description John is the only priest in his town. September 1st is the Jo ...

  3. poj3683 2-sat Priest John's Busiest Day

    Description John is the only priest in his town. September 1st is the John's busiest day in a year b ...

  4. Priest John's Busiest Day(POJ 3683)

    原题如下: Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12162   ...

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

  6. poj 3686 Priest John's Busiest Day

    http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...

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

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

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

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

  9. POJ3683 Priest John's Busiest Day(2-SAT)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11049   Accepted: 3767   Special Judge ...

随机推荐

  1. 在Linux/Centos下用wondershaper限速

    wondershaper是国外人开发的一款在Linux内核下基于TC工具的对整块网卡的限度工具,虽然有很久没有更新了,但是测试老版本在Centos6.3上依然可以使用. 首先下载wondershape ...

  2. 打开word时出现the setup controller has encountered a problem during install解决办法

    问题电脑为win7,office是默认安装 删除下面文件夹即可解决该问题 C:\Program Files\Common Files\Microsoft Shared\OFFICE12\Office ...

  3. filezilla server客户端FTP连接不上解决

    windows服务器上安装Filezilla server后,本地客户端连接不上.解决办法: 1.在防火墙把filezilla的 Filazilla server interface.exe 和Fil ...

  4. go 开发环境安装教程 windows

         首先进入go 语言官网下载最新安装包,我目前安装的版本是 1.8.3版本:go1.8.3.windows-amd64.msi 如果下载慢,这个是百度云地址:https://pan.baidu ...

  5. 你所有不知的margin属性

    前言 致谢 本文总结于 张鑫旭老师的 CSS深入理解之margin课程,感谢张老师的辛苦付出! 难学的 CSS 作为前端狗的我们,每天都要和网页打交道.当 UI 将设计稿发给你时,CSS 的知识便显得 ...

  6. numpy模块中的sum(axis)方法

    1.sum函数声明 sum(a, axis=None, dtype=None, out=None, keepdims=<class 'numpy._globals._NoValue'>) ...

  7. 2017第八届蓝桥杯 K倍区间

    标题: k倍区间 给定一个长度为N的数列,A1, A2, - AN,如果其中一段连续的子序列Ai, Ai+1, - Aj(i <= j)之和是K的倍数,我们就称这个区间[i, j]是K倍区间. ...

  8. 理解OAuth2.0认证

    一.什么是OAuth协议 OAuth 协议为用户资源的授权提供了一个安全的.开放而又简易的标准.与以往的授权方式不同之处是 OAuth的授权不会使第三方触及到用户的帐号信息(如用户名与密码),即第三方 ...

  9. 网站入住各大搜索引擎的seo优化技巧

    最近在公司上班的时候做了一个工业物联网的项目,上层主管提出要求,让这个网站入住各大搜索引擎,也就是说在各大搜索引擎中输入与网站相关的关键字就能搜索到我们自己的网站.刚开始自己一脸懵逼,因为之前自己并没 ...

  10. java 集合框架(二)Iterable接口

    Iterable接口是java 集合框架的顶级接口,实现此接口使集合对象可以通过迭代器遍历自身元素,我们可以看下它的成员方法 修饰符和返回值 方法名 描述 Iterator<T> iter ...