转换成2-SAT模型,建边是如果时间(i,j)冲突就连边(i,j'),其他同理 tarjan缩点,判可行性 返图拓扑,输出方案 #include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<queue> using namespace std; const int N=5005; int n,a[N],b[N],h[N],cnt,dfn[N],low…
POJ 3683 Priest John's Busiest Day / OpenJ_Bailian 3788 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 because there is an old legend in the town that the couple w…
Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10010   Accepted: 3425   Special Judge Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old l…
Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6900   Accepted: 2363   Special Judge Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old le…
Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples…
题意:有N场婚礼,每场婚礼的开始时间为Si,结束时间为Ti,每场婚礼有个仪式,历时Di,这个仪式要么在Si时刻开始,要么在Ti-Di时刻开始,问能否安排每场婚礼举行仪式的时间,使主持人John能参加所有的这些仪式的全过程. 题目链接:http://poj.org/problem?id=3683 ——>>每场婚礼的仪式,要么在开始段举行,要么在结束段举行,且一定要举行,要求各场婚礼仪式没冲突——>>2-SAT... 2-SAT挺神,针对此类问题,可谓手到擒来... LJ<训练指…
题意:有n对新人要在同一天结婚.结婚时间为Ti到Di,这里有时长为Si的一个仪式需要神父出席.神父可以在Ti-(Ti+Si)这段时间出席也可以在(Di-Si)-Si这段时间.问神父能否出席所有仪式,如果可以输出一组时间安排. 思路:2-SAT.神父可以在开始出席也可以在结束时候出席,要求与其他出席时间没有冲突,这样建图计算即可.另一一定要弄清楚true和false代表的含义. #include <cstdio> #include <cmath> #include <vecto…
题意: 一些人要在同一天进行婚礼,但是牧师只有1个,每一对夫妻都有一个时间范围[s , e]可供牧师选择,且起码要m分钟才主持完毕,但是要么就在 s 就开始,要么就主持到刚好 e 结束.因为人数太多了,这些时间可能会重叠,可能还会完全包含,可能还没有交叉,各种情况.问牧师能否主持完全部人的婚礼,若可以,给出每对夫妻占用牧师的一个时间段(记得按所给的夫妻的顺序哦). 主要步骤如下. (1)先建原图,不管是否会冲突. (2)找强连通分量来缩点,如果会冲突,这个时候应该发现. (3)建个缩点后,原图的…
2-SAT简单题,判断一下两个开区间是否相交 #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<stack> #include<algorithm> using namespace std; +; int N,M; struct Time { int Start; int End; int…
题意: $n$对$couple$举行仪式,有两个时间段可以选择,问是否可以不冲突举行完,并求方案 两个时间段选择对应一真一假,对于有时间段冲突冲突的两人按照$2-SAT$的规则连边(把不冲突的时间段连起来) 然后本题需要构造解,所以要$SCC$缩点反向建图记录否定再拓扑排序$dfs$染色,好麻烦... #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #…
这是一道裸的2-Sat,只要考虑矛盾条件的判断就好了. 矛盾判断: 对于婚礼现场 x 和 y,x 的第一段可以和 y 的第一段或者第二段矛盾,同理,x 的第二段可以和 y 的第一段或者第二段矛盾,条件是 x 的 1或2 段与 y 的 1或2 段有重合,那么选了 x 某一段就不能选择其矛盾的那一段,那就只能选择 y 中的另一段,建立一条 x (u)-> y ( v的对立 ),同理,x (u的对立)<- y ( v ) . 真的,2-sat千万不要用邻接链表!!!卡死卡死卡死!!!稠密图!!!不要…
看这个题目之前可以先看POJ2186复习一下强联通分量的分解 题意:给出N个开始时间和结束时间和持续时间三元组,持续时间可以在开始后或者结束前,问如何分配可以没有冲突. -----–我是分割线----------- 先解释一下合取范式(离散数学已经学过): 如果合取范式中的每个字句的文字个数不超过两个就称为2-SAT问题 一般性称为n-SAT问题 举个栗子:(a∨b)∧¬a" role="presentation" style="position: relative…
http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948.html 注: 本代码在判断两个时间段部分有误,数据弱A了 #include<cstdio> #include<vector> using namespace std; #define N 1001 struct TIME { int h1,m1; int h2,m2; int tim…
题目地址:POJ 3683 第一次做须要输出可行解的题目. . .大体思路是先用强连通来推断是否有可行解,然后用逆序建图.用拓扑排序来进行染色.然后输出可行解. 详细思路见传送门 由于推断的时候少写了一个等号..检查了好长时间..sad... 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h>…
题目 John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples plan to g…
原题如下: Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12162   Accepted: 4138   Special Judge Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an…
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 because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God o…
Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11049   Accepted: 3767   Special Judge Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the…
Description John is the only priest in his town. October 26th is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples p…
Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples…
题目 John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples plan to g…
题面 John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples plan to g…
强连通算法推断是否满足2-sat,然后反向建图,拓扑排序+染色. 一种选择是从 起点開始,还有一种是终点-持续时间那个点 開始. 若2个婚礼的某2种时间线段相交,则有矛盾,建边. easy出错的地方就在于推断线段相交. 若s1<e2&&s2<e1则相交 输出路径的做法能够參考论文2-SAT解法浅析 #include <iostream> #include<cstring> #include<cstdio> #include<string…
贪心.. #include<iostream> #include<string.h> #include<math.h> #include <stdio.h> #include <algorithm> using namespace std; struct node { int s,t; int m; }; node a[]; int cmp(node a,node b) { return a.m<b.m; } int main() { in…
2-SAT 输出可行解 找可行解的方案就是: 根据第一次建的图建一个反图..然后求逆拓扑排序,建反图的原因是保持冲突的两个事件肯定会被染成不同的颜色 求逆拓扑排序的原因也是为了对图染的色不会发生冲突,输出可行解就是遍历一次逆拓扑排序时染成的颜色,输出同一组颜色的解就是其中的一组可行解.   代码: #include <stdio.h> #include <iostream> #include <string.h> #include <stack> #incl…
2-SAT. 读入用了黄学长的快速读入,在此膜拜感谢. 把每对时间当作俩个点.如果有交叉代表相互矛盾. 然后tarjan缩点,这样就能得出当前的2-SAT问题是否有解. 如果有解,跑拓扑排序就能找出一个特定的解. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; + ; + ; inline int read() //by hzwer 实在太好了..我用下..跪谢. {…
题意 n对夫妻要结婚,第i对夫妻结婚的婚礼持续时间为[Si, Ti],他们会举行一个仪式,仪式时间为Di,这个仪式只能举行在开头或者结尾举行,要么[Si, Si+Di],要么[Ti-Di, Ti],然而举行仪式的牧师只有一个,问牧师能否举行完所有仪式 按输入顺序输出方案 手动翻译 Sol \(2-SAT\)输出一组可行解 这个很烦 \(Tarjan\)缩点成\(DAG\)后再拓扑排序+染色 只传递不选的标记 # include <iostream> # include <stdio.h&…
题意简介 有一个司仪,要主持n场婚礼,给出婚礼的起始时间和终止时间,每个婚礼需要超过一半的时间做为仪式,并且仪式不能终止.问说司仪能否主持n场婚礼. 输入格式 多组数据,每组数据输入一个\(N\)(\(N\)<=100000),接下来N行,每行输入\(Si\),\(Ti\)两个数,当输入\(n=0\)时输入结束 输出格式 每行对应每组数据,用"YES"或"NO"代表能否主持完n场婚礼 算法分析 一眼贪心,要求主持完全部婚礼,每个婚礼主持时间为 \((Ti-Si…
Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8872   Accepted: 3027   Special Judge Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old le…
Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11127   Accepted: 3785   Special Judge Description John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old l…