题意

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内核中修改TCP MSS值

    MTU: Maxitum Transmission Unit 最大传输单元 MSS: Maxitum Segment Size 最大分段大小 MSS最大传输大小的缩写,是TCP协议里面的一个概念.MS ...

  2. bzoj 2073 暴力

    2073: [POI2004]PRZ Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 442  Solved: 327[Submit][Status][D ...

  3. Yii2中JSONP跨域问题的解决

    Jsonp(JSON with Padding) 是 json 的一种"使用模式",可以让网页从别的域名(网站)那获取资料,即跨域读取数据. 为什么我们从不同的域(网站)访问数据需 ...

  4. FFMpeg for PHP

    PHP使用FFMpeg来转换视频格式.Github上搜索FFMPEG,到https://github.com/PHP-FFMpeg/PHP-FFMpeg. For Windows users : Pl ...

  5. hdu1061(2015-N1):1.快速幂;2.找规律

    1.快速幂 原理:求a的b次方,将b转化为二进制数,该二进制位第i位的权是2^(i-1), 例如 11的二进制是1011 11 = 2³×1 + 2²×0 + 2¹×1 + 2º×1 因此,我们将a¹ ...

  6. FineUIPro控件库深度解析

    FineUIPro控件库 FineUIPro是一套基于jQuery的专业ASP.NET控件库,始于2008年的开源版FineUI控件库. 当年为了提升项目的开发效率,降低代码复杂度,减少对CSS和Ja ...

  7. 企业内部DNS跨国配置案例

    背景介绍:总公司与北京分公司均由总公司进行统一管理.总公司的主从DNS担任解析总公司服务器与北京分公司的服务器解析任务.总公司DNS委派其他两个公司管理自己域下的服务器解析任务.要求任何一个节点都能解 ...

  8. 妙用ES6解构和扩展运算符让你的代码更优雅

    http://www.cnblogs.com/chrischjh/p/4848934.html

  9. html、text、val、attr、prop区别。this.value和$(this).val()区别以及return用法

    html(): html() 方法返回或设置被选元素的内容 (inner HTML). 当使用该方法读取多个值时,它会返回第一个匹配元素的内容. 当使用该方法设置一个值时,它会覆盖所有匹配元素的内容. ...

  10. spring schedule定时任务(二):配置文件的方式

    接着上一篇,这里使用spring配置文件的方式生成spring定时任务. 1.相应的web.xml没有什么变化,因此便不再罗列.同样的,相应的java代码业务逻辑改动也不大,只是在原来的基础上去掉@C ...