Poj3683:Priest John's Busiest Day
题意
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的更多相关文章
- 【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-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 ...
- 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 ...
- Priest John's Busiest Day(POJ 3683)
原题如下: Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12162 ...
- 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 3686 Priest John's Busiest Day
http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...
- 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+方案输出)
Priest John's Busiest Day Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10010 Accep ...
- POJ3683 Priest John's Busiest Day(2-SAT)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11049 Accepted: 3767 Special Judge ...
随机推荐
- block,inline,inline-block的区别
最近正在复习,紧张地准备几天后的笔试,然后刚好看到这个地方. block:块级元素,会换行,如div,p,h1~h6,table这些,可以设置宽高: inline:行内元素,不换行,挤在一行显示 ...
- Docker 中国官方镜像加速
参考:https://www.docker-cn.com/registry-mirror 通过 Docker 官方镜像加速,中国区用户能够快速访问最流行的 Docker 镜像.该镜像托管于中国大陆,本 ...
- 使用腾讯云“自定义监控”监控GPU使用率
欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 作者:李想 随着人工智能以及比特币的火热,GPU云服务的使用场景是越来越广,在很多场景下我们也需要获取GPU服务器的性能参数来优化程序的执行.目 ...
- EntityFrameWork连接多Db配置
如题所示,EF作为微软主推的ORM工具,最新版本已经是7,说明有很多人在使用它做项目.在使用过程中,可能会连接不同的数据库,本文介绍的是连接SqlServer,MySql和SQLite三种,并且可以互 ...
- typeof操作符 返回值
Type操作符 返回值 : 1undefined 这个未定义 2.boolean 这个为boolean类型 3.string 这个是字符串 4.number 这个就是数值 5 ...
- iOS实现从服务器请求json数据并转化成NSDictionary
NSURL *url = [NSURL URLWithString:URL]; NSURLRequest *request = [NSURLRequest requestWithURL:url cac ...
- MyCat 枚举分片设计思考,查询命中条件
Mycat多租户实现的两种方式 MyCat,各种分片规则,仅保证插入的时候分片.表关联,join,查询怎么命中分片条件,还是需要设计. 今天稍微测了一下. ER 分片,此方式,插入的时候能分片,但是查 ...
- 使用C#解决部分Win8.1系统窗口每隔几秒失去焦点的问题【转】
使用了Win8.1 With Update 1后,发现重启系统后,当前激活的窗口总是每隔几秒失去焦点,过0.5~1秒焦点回来,导致输入无法正常工作,严重影响使用心情和效率. 在网上找了很久,也没找到相 ...
- 3.3.5 DMA写时发生Cache命中的优化
在许多高性能处理器中,还提出了一些新的概念,以加速外设到存储器的DMA写过程.如Freescale的I/O Stashing和Intel的IOAT技术. 如图3?8所示,当设备进行存储器写时,如果可以 ...
- Android之PendingIntent的深入理解
PendingIntent字面意义:等待的,未决定的Intent.要得到一个pendingIntent对象,使用方法类的静态方法 getActivity(Context, int, Intent, i ...