http://poj.org/problem?id=3678

总觉得这题比例题简单。

设a为x取0的点,a+n为x取1的点。

我们还是定义a到b表示取a必须取b。

那么我们有:

当AND:

1.当c=1:add(a,a+n); add(b,b+n);//我们不能取0的点,所以我们让程序一旦取0必会矛盾,下面类似的同理。

2.当c=0:add(a+n,b); add(b+n,a);

当OR

1.当c=1:add(a,b+n);add(b,a+n);

2.当c=0:add(a+n,a);add(b+n,b);

当OR

1.当c=1:add(a+n,b);add(b+n,a);add(a,b+n); add(b,a+n);

2.当c=0:add(a+n,b+n);add(b+n,a+n);add(a,b);add(b,a);

剩下的就是2-SAT(tarjan缩点)的活了。

#include<stack>
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
int x=,w=;char ch=;
while(ch<''||ch>''){if(ch=='-')w=-;ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*w;
}
const int N=;
const int M=;
struct node{
int to;
int nxt;
}edge[M*];
int head[N],dfn[N],low[N],to[N];
int n,m,t,l,cnt;
bool instack[N*];
stack<int>q;
inline void add(int u,int v){
cnt++;
edge[cnt].to=v;
edge[cnt].nxt=head[u];
head[u]=cnt;
return;
}
void tarjan(int u){
t++;
dfn[u]=t;
low[u]=t;
q.push(u);
instack[u]=;
for(int i=head[u];i!=;i=edge[i].nxt){
int v=edge[i].to;
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}else if(instack[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(low[u]==dfn[u]){
int v;
l++;
do{
v=q.top();
q.pop();
instack[v]=;
to[v]=l;
}while(v!=u);
}
return;
}
//a为x取0的点,a+n为x取1的点
int main(){
int n=read();
int m=read();
for(int i=;i<=m;i++){
int a=read();
int b=read();
int c=read();
char op[];
scanf("%s",op);
if(op[]=='A'){
if(c){
add(a,a+n);
add(b,b+n);
}else{
add(a+n,b);
add(b+n,a);
}
}
if(op[]=='O'){
if(c){
add(a,b+n);
add(b,a+n);
}else{
add(a+n,a);
add(b+n,b);
}
}
if(op[]=='X'){
if(c){
add(a+n,b);
add(b+n,a);
add(a,b+n);
add(b,a+n);
}else{
add(a+n,b+n);
add(b+n,a+n);
add(a,b);
add(b,a);
}
}
}
for(int i=;i<n*;i++){
if(!dfn[i])tarjan(i);
}
for(int i=;i<n;i++){
if(to[i]==to[i+n]){
printf("NO\n");
return ;
}
}
printf("YES\n");
return ;
}

POJ3678:Katu Puzzle——题解的更多相关文章

  1. POJ3678 Katu Puzzle 【2-sat】

    题目 Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean ...

  2. poj3678 Katu Puzzle 2-SAT

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6714   Accepted: 2472 Descr ...

  3. POJ-3678 Katu Puzzle 2sat

    题目链接:http://poj.org/problem?id=3678 分别对and,or,xor推出相对应的逻辑关系: 逻辑关系 1 0  A and B     A'->A,B'->B ...

  4. POJ3678 Katu Puzzle

    原题链接 \(2-SAT\)模板题. 将\(AND,OR,XOR\)转换成\(2-SAT\)的命题形式连边,用\(tarjan\)求强连通分量并检验即可. #include<cstdio> ...

  5. POJ 3678 Katu Puzzle(2-SAT,合取范式大集合)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9987   Accepted: 3741 Descr ...

  6. 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 ...

  7. 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 ...

  8. POJ 3678 Katu Puzzle (2-SAT)

                                                                         Katu Puzzle Time Limit: 1000MS ...

  9. POJ 3678 Katu Puzzle (经典2-Sat)

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2401 Descr ...

随机推荐

  1. SpringBoot学习:整合shiro(rememberMe记住我功能)

    项目下载地址:http://download.csdn.NET/detail/aqsunkai/9805821 首先在shiro配置类中注入rememberMe管理器 /** * cookie对象; ...

  2. hdu1045Fire Net(经典dfs)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. [wirtting] top01 independent

    Do you agree or disagree with the following statement? At universities and colleges, sports and soci ...

  4. Siki_Unity_3-13_编程内功修炼-算法

    Unity 3-13 编程内功修炼 -- 算法 任务1&2:课程介绍 主要算法: 分治法 堆排序 二叉树 动态规划 贪心算法 图 任务3:分治算法 -- Divide and Conquer ...

  5. 一篇文章让你了解GC垃圾回收器

    简单了解GC垃圾回收器 了解GC之前我们首先要了解GC是要做什么的?顾名思义回收垃圾,什么是垃圾呢? GC回收的垃圾主要指的是回收堆内存中的垃圾对象. 从根对象出发,所有被引用的对象,都是存活对象 其 ...

  6. Python数据分析实战-Boston Public Schools GEO数据分析-Part1

    项目目标: Boston Public Schools Geo数据是来自于Boston地区的公共学校的数据,具体描述了学校的坐标,名字,类型等.基于此数据,我们可以学习一些基本的Python数据分析的 ...

  7. 90 [LeetCode] Subsets2

    Given a collection of integers that might contain duplicates, nums, return all possible subsets (the ...

  8. 深度学习笔记 (一) 卷积神经网络基础 (Foundation of Convolutional Neural Networks)

    一.卷积 卷积神经网络(Convolutional Neural Networks)是一种在空间上共享参数的神经网络.使用数层卷积,而不是数层的矩阵相乘.在图像的处理过程中,每一张图片都可以看成一张“ ...

  9. UVa -1584 Circular Sequence 解题报告 - C语言

    1.题目大意 输入长度为n$(2\le n\le 100)$的环状DNA串,找出该DNA串字典序最小的最小表示. 2.思路 这题特别简单,一一对比不同位置开始的字符串的字典序,更新result. 3. ...

  10. KVM存储虚拟化---玩转openstack

    KVM 的存储虚拟化是通过存储池(Storage Pool)和卷(Volume)来管理的. Storage Pool 是宿主机上可以看到的一片存储空间,可以是多种类型,后面会详细讨论.Volume 是 ...