CF776D The Door Problem [2sat]】的更多相关文章

翻译 对于一扇门,如果是关的,那么他必须使用其中一个开关开开来,如果是开的,要么使用两个开关,要么啥都不做.这样,每扇门恰好对应两种状态,要选一个. 考虑用2-SAT模型解决.连边的话是对于一个机关,所有他控制的门都应该一起选(具体地说,对于一扇关闭的门,这个机关是他的第几个机关,就是哪个状态,如果是开着的,必须对应使用开关两次的状态),所以这些状态点互相连双向边. #include<iostream> #include<cstdio> #include<cstring>…
考虑 \(\texttt{2-SAT}\) 首先每个门 \(i\) 都有一个初始状态 \(a_i\) 题目条件每个门只被两个开关控制,那么很显然的 \(\texttt{2-SAT}\) 用 \(b_{i,{0/1}}\)记录是第 \(1/2\) 个开关 然后就考虑一下门的初始状态 \(a_i\) 门本身是开的 你开这个开关为开,另一个也要是开的, 反之亦然,所以建两对双向边 门本身是关的 你开这个开关为开,另一个必须是关的 反之亦然,所以还是建两对双向边 然后根据 \(\texttt{2-SAT…
题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Moriarty has trapped n people in n distinct rooms in a hotel. Some room…
思路: 并查集维护每个开关的状态on[i]和off[i] .假设灯L由开关S1和S2控制.如果开关是亮的,则S1和S2的状态相反:如果开关是灭的,则S1和S2的状态相同.当一个开关状态已知时,可以得知另一个开关的状态,合并.如果on[i]和off[i]在同一个集合就无解.时间复杂度:O((n+m)α(n)).当然也可以二分图判定. #include<cstdio> #define on(i) i #define off(i) i+m ,N=; class DisjointSet { priva…
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! 题目链接:CF776D 正解:$2-SAT$ 解题报告: 似乎以前做过类似的题啊,不过因为没有正好$2$个这个限制所以并不好做. 考虑题目相当于是问是否存在使得每个点都变成$0$的的方案,一次操作我们可以看成是一次异或. 因为有一个强有力的限制条件,我们就…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=44  Maximum Sum  Background A problem that is simple to solve in one dimension is often much more difficult to solve in more th…
A problem that is simple to solve in one dimension is often much more difficult to solve in more than one dimension. Consider satisfying a boolean expression in conjunctive normal form in which each conjunct consists of exactly 3 disjuncts. This prob…
再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所以用并查集亦可. #include<cstdio> #include<vector> #include<cstring> using namespace std; vector<int>G[200010],rG[200010],vs; bool used[200…
Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2951    Accepted Submission(s): 984 Problem Description Robbie is playing an interesting computer game. The game field is an unbounded…
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1997 分析: 考虑每条边是在圈子里面还是圈子外面 所以就变成了2-SAT判定问题了= =,于是求SCC,如果一个点对应的2个bool点在一个SCC中就无解了. 当然这样建图好像要TLE…… 然后就要上大杀器了:平面图|E|<=3|V|-6 所以,如果m>3n-6就直接输出NO了…
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1732    Accepted Submission(s): 751 Problem Description Conflicts are everywhere in the world, from the young to the elder…
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1315    Accepted Submission(s): 563 Problem Description Conflicts are everywhere in the world, from the young to the elder…
题意:有N场婚礼,每场婚礼的开始时间为Si,结束时间为Ti,每场婚礼有个仪式,历时Di,这个仪式要么在Si时刻开始,要么在Ti-Di时刻开始,问能否安排每场婚礼举行仪式的时间,使主持人John能参加所有的这些仪式的全过程. 题目链接:http://poj.org/problem?id=3683 ——>>每场婚礼的仪式,要么在开始段举行,要么在结束段举行,且一定要举行,要求各场婚礼仪式没冲突——>>2-SAT... 2-SAT挺神,针对此类问题,可谓手到擒来... LJ<训练指…
http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7021   Accepted: 2604 Description liympanda, one of Ikki’s friend, likes playing games with Ikki. Today after minesweeping wi…
题目链接:http://poj.org/problem?id=3648‘ 题意:一对情人举行婚礼,有n对夫妇参加,别人对着坐在一个长桌子的两边,新娘和新郎坐在最后面,新娘只能看见坐在他对面的人.现在,n对夫妇中有两两通奸了,新娘不希望看到这种情况,先给出通奸的人,求是否存在可行的排位方法. 有两种建立2sat模型的方法,第一种是对每个人的坐的方向来建立,0和1分别表示坐在左边和右边.但是可以不考虑坐方向,只考虑他们能不能坐在同一边,需要考虑新郎的一边,因为新娘那边得不出限制条件. //STATU…
题目链接:http://poj.org/problem?id=2296 二分+2sat,每个点的上下两个方向为2sat的两个状态. //STATUS:C++_AC_16MS_536KB #include <functional> #include <algorithm> #include <iostream> //#include <ext/rope> #include <fstream> #include <sstream> #in…
题目链接:http://poj.org/problem?id=3207 题意:在一个圆圈上有n个点,现在用线把点两两连接起来,线只能在圈外或者圈内,现给出m个限制,第 i 个点和第 j 个点必须链接在一起,问是否存在可行解. 容易想到圈内和圈外分别表示2sat的两种状态,对每一个限制 i 和 j ,考虑所有其它横跨他们的限制,然后连边就可以了. //STATUS:C++_AC_47MS_6300KB #include <functional> #include <algorithm>…
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18511 [思路] 2-SAT. 设分得A或B类任务为1 C类任务为0,考虑互相讨厌的两人:如果年龄阶段相同,则需要满足a!=b,即(a==1 or b==1)=1 && (a==0 or b==0)=1,如果年龄阶段不同,则需要满足ab不同时为C,即(a==1 or b==1)=1. [代码] #include<cstdio> #include&…
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33799 [思路] 2-SAT. 二分安全间隔x,先到为1后到为0,则唯一的限制即两个不同的时间a b如果其间隔小于x则不能满足(a=1 and b=1),即满足 (a or b)=1,如果满足所有的约束条件则x可行. 时间复杂度为O(logt*n^2). [代码] #include<cstdio> #include<vector> #include&…
Building roads Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6229   Accepted: 2093 Description Farmer John's farm has N barns, and there are some cows that live in each barn. The cows like to drop around, so John wants to build some ro…
Problem Description   This year is the 60th anniversary of NJUST, and to make the celebration more colorful, Tom200 is going to invite distinguished alumnus back to visit and take photos.   After carefully planning, Tom200 announced his activity plan…
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2269">题目链接 题意:有n对夫妻參加一个婚宴. 全部人都坐在一个长长的餐桌的左边或者右边.全部夫妻都仅仅能面对面坐,包含新娘和新郎.新娘仅仅能看到坐在她不同側的人.有m对人超过架,新娘不希望看到他们坐在同一側. 问有没有分配方案满足新娘的要求. 思路:2-SAT问题.如果每对夫妇为一个变量xi.如果xi为true时,妻子与新娘坐同一側:xi为fa…
Peaceful Commission Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1948    Accepted Submission(s): 560 Problem Description The Public Peace Commission should be legislated in Parliament of Th…
http://hihocoder.com/contest/hiho133/problem/1 2-sat模板...详细的题解请看题目里的提示. tarjan模板打错again致命伤qwq #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 103; const int M = 1003; bool inst[N << 1]; str…
POJ 2296 Map Labeler / ZOJ 2493 Map Labeler / HIT 2369 Map Labeler / UVAlive 2973 Map Labeler(2-sat 二分) Description Map generation is a difficult task in cartography. A vital part of such task is automatic labeling of the cities in a map; where for e…
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…
POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题) Description liympanda, one of Ikki's friend, likes playing games with Ikki. Today after minesweeping with Ikki and winning so many times, he is tired of such easy games and wants to play another game…
HDU 1814 Peaceful Commission / HIT 1917 Peaceful Commission /CJOJ 1288 和平委员会(2-sat模板题) Description The Public Peace Commission should be legislated in Parliament of The Democratic Republic of Byteland according to The Very Important Law. Unfortunatel…
http://www.lydsy.com/JudgeOnline/problem.php?id=2199 题意:裸的2-SAT,但是问每个变量在所有解中是只能为真还是只能为假还是既可以为真又可以为假 这样的话求$SCC$的做法就不好做了 于是只能用$naive$做法了,枚举每个变量选择真假然后$dfs$一遍看看是否可行 点从2开始,然后就可以愉快的异或啦 #include <iostream> #include <cstdio> #include <cstring> #…
Problem   UVALive - 3713 - Astronauts Time Limit: 3000 mSec Problem Description Input The input contains several blocks of test cases. Each case begins with a line containing two integers 1 ≤ n ≤ 100000 and 1 ≤ m ≤ 100000. The number n is the number…