POJ-3678 Katu Puzzle 2sat
题目链接:http://poj.org/problem?id=3678
分别对and,or,xor推出相对应的逻辑关系:
逻辑关系 1 0
A and B A'->A,B'->B A->B',B->A'
A or B A'->B',B'->A A->A',B->B'
A xor B A'->B,B'->A,A->B',B->A' A->B,A'->B'
//STATUS:C++_AC_96MS_472KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int first[N*],next[N*N*],vis[N*],S[N*];
int n,m,mt,cnt; struct Edge{
int u,v;
}e[N*N*]; void adde(int a,int b)
{
e[mt].u=a,e[mt].v=b;
next[mt]=first[a];first[a]=mt++;
} int dfs(int u)
{
if(vis[u^])return ;
if(vis[u])return ;
int i;
vis[u]=;
S[cnt++]=u;
for(i=first[u];i!=-;i=next[i]){
if(!dfs(e[i].v))return ;
}
return ;
} int Twosat()
{
int i,j;
mem(vis,);
for(i=;i<n;i+=){
if(vis[i] || vis[i^])continue;
cnt=;
if(!dfs(i)){
while(cnt)vis[S[--cnt]]=;
if(!dfs(i^))return ;
}
}
return ;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,a,b,c;
char op[];
while(~scanf("%d%d",&n,&m) && (n||m))
{
n<<=;
mem(first,-);mt=;
while(m--){
scanf("%d%d%d%s",&a,&b,&c,op);
a<<=,b<<=;
if(op[]=='A'){
if(c){
adde(a^,a);
adde(b^,a);
}
else {
adde(a,b^);
adde(b,a^);
}
}
else if(op[]=='O'){
if(c){
adde(a^,b);
adde(b^,a);
}
else {
adde(a,a^);
adde(b,b^);
}
}
else {
if(c){
adde(a^,b);
adde(b^,a);
adde(a,b^);
adde(b,a^);
}
else {
adde(a,b);
adde(a^,b^);
}
}
} printf("%s\n",Twosat()?"YES":"NO");
}
return ;
}
POJ-3678 Katu Puzzle 2sat的更多相关文章
- poj 3678 Katu Puzzle(2-sat)
Description Katu Puzzle ≤ c ≤ ). One Katu ≤ Xi ≤ ) such that for each edge e(a, b) labeled by op and ...
- poj 3678 Katu Puzzle 2-SAT 建图入门
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
- POJ 3678 Katu Puzzle 2-SAT 强连通分量 tarjan
http://poj.org/problem?id=3678 给m条连接两个点的边,每条边有一个权值0或1,有一个运算方式and.or或xor,要求和这条边相连的两个点经过边上的运算后的结果是边的权值 ...
- POJ 3678 Katu Puzzle(2-SAT,合取范式大集合)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9987 Accepted: 3741 Descr ...
- POJ 3678 Katu Puzzle (经典2-Sat)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6553 Accepted: 2401 Descr ...
- POJ 3678 Katu Puzzle (2-SAT)
Katu Puzzle Time Limit: 1000MS ...
- POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
- POJ 3678 Katu Puzzle (2-SAT,常规)
题意:给出n个点,每个点上有一个数字可以0或1,然后给出m条限制,要求a和b两个点上的数字满足 a op b = c,op和c都是给定.问是否能够有一组解满足所有限制?(即点上的数字是0是1由你决定) ...
- poj 3678 Katu Puzzle(Two Sat)
题目链接:http://poj.org/problem?id=3678 代码: #include<cstdio> #include<cstring> #include<i ...
- POJ 3678 Katu Puzzle
Description 给出一个关系,包括 And,Xor,Or 问是否存在解. Sol 经典的2-SAT问题. 把每个值看成两个点,一个点代表选 \(0\) ,另一个代表选 \(1\) . 首先来看 ...
随机推荐
- WPF杂难解 奇怪的DisconnectedItem
简单场景: 列表绑定后台数据,点击列表项在view的cs中拿点击项的DataContext进一步处理.正常情况下应该是能拿到我绑定上去的数据,但是偶尔会点出来DisconnectedItem,重现几率 ...
- 使用Result代替ResultSet作为方法返回值
在开发过程中,我们不能将ResultSet对象作为方法的返回值,因为Connection连接一旦关闭,在此连接上的会话和在会话上的结果集也将会自动关闭,而Result对象则不会发生这种现象,所以在查询 ...
- 【springmvc Request】 springmvc请求接收参数的几种方法
通过@PathVariabl注解获取路径中传递参数 转载请注明出处:springmvc请求接收参数的几种方法 代码下载地址:http://www.zuida@ima@com/share/1751862 ...
- XSS之学习误区分析
有段时间没写东西了, 最近看到zone里出现了很多“XSS怎么绕过某某符号的帖子”,觉得很多新手在寻找XSS时走进了一些误区,比如:专门想着怎么去“绕过”.这里做个总结,希望对大家有所帮助. 1. 误 ...
- 双缓冲(Double Buffer)原理和使用
转自双缓冲(Double Buffer)原理和使用 一.双缓冲作用 双缓冲甚至是多缓冲,在许多情况下都很有用.一般需要使用双缓冲区的地方都是由于"生产者"和& ...
- Ubuntu14.04建立WiFi热点
整理自Ubuntu 下建立WiFi热点的方法 Ubuntu14.04 Deepin2014分享WiFi 亲测成功 方法一:network manager 用Ubuntu自带的network manag ...
- MySQL函数讲解(MySQL函数大全)
讲mysql函数之前先给大家展示一下利用mysql函数的一个例子: SELECT i.item_id, i.item_name, i.cid, i.last_update_time, u.url, u ...
- public void Delete(List EntityList) where T : class, new()类型参数约束
查找后发现这是类型参数约束,.NET支持的类型参数约束有以下五种: where T : struct | T必须是一个结构类型 where T : class T必须是一个类(class)类型 whe ...
- Linux用户行为日志审计
http://my.oschina.net/xiangpang/blog/532999 http://my.oschina.net/chaichuan/blog/508494 http://my.os ...
- UAC新解(有非正常手段可以绕过)
360第一次注册是需要弹,可是以后就不弹了开机自启动不弹框,开机自启动不弹框 服务是system权限再说一句,一般程序也不需要过UAC系统启动项白名单.UAC有一个白名单机制.还有UAC也可以通过wu ...