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…
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…
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<训练指…
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…
题意:有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)建个缩点后,原图的…
题意: $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…
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…
转换成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…
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>…
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…
题目 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…
Priest John's Busiest Day Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1420    Accepted Submission(s): 415 Problem Description John is the only priest in his town. October 26th is the John's…
id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 12244   Accepted: 3861 Description The galaxy war between the Empire Draco and the Commonwealth of…
POJ 3083 -- Children of the Candy Corn(DFS+BFS) 题意: 给定一个迷宫,S是起点,E是终点,#是墙不可走,.可以走 1)先输出左转优先时,从S到E的步数 2)再输出右转优先时,从S到E的步数 3)最后输出S到E的最短步数 解题思路: 前两问DFS,转向只要控制一下旋转方向就可以 首先设置前进方向对应的数字 向上——N——0 向右——E——1 向下——S——2 向左——W——3 比如说右转优先,即为向右,向前,向左,向后,即逆时针方向for(int i…
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. 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…
题意简介 有一个司仪,要主持n场婚礼,给出婚礼的起始时间和终止时间,每个婚礼需要超过一半的时间做为仪式,并且仪式不能终止.问说司仪能否主持n场婚礼. 输入格式 多组数据,每组数据输入一个\(N\)(\(N\)<=100000),接下来N行,每行输入\(Si\),\(Ti\)两个数,当输入\(n=0\)时输入结束 输出格式 每行对应每组数据,用"YES"或"NO"代表能否主持完n场婚礼 算法分析 一眼贪心,要求主持完全部婚礼,每个婚礼主持时间为 \((Ti-Si…
题意:给出 n ,k 表示接下来给你 n 段开区间,每段区间都有它的权值,问选出一些区间,使它的权值最大,并且在实轴上的每个点,不得超过 k次被覆盖. 思路:首先要理解建图思路,首先有一个基图,相邻点之间都有边,花费为0,容量为 k,然后再根据所给数据 u,v, w 建图,u,v,加一条容量为 1,花费为 - w的边,求最大费用最大流,只需将权值变为负数即可求出最短路,相反数即为最大值. 最小费用最大流,就是用SPFA寻找最短路(增广路容量是否大于流量,花费最短路),然后用最大流方法去计算最大流…
关于two sat算法 两篇很好的论文由对称性解2-SAT问题(伍昱), 赵爽 2-sat解法浅析(pdf). 一些题目的题解 poj 3207 poj 3678 poj 3683 poj 3648 poj 2723 poj 2749 关于具体算法 首先此算法只对于存在类似于一个点选了另一个点就不能选这样的条件,并且每个点只有两种状态(一般是选或不选),不然是个NP问题 大体做法就是先转换模型,把每个点拆成两个,一个代表取,一个代表不取,(注意:图中边代(u->v)代表取u就一定要取v) 至于判…
强连通算法推断是否满足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…