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. Linux系统中ElasticSearch搜索引擎安装配置Head插件

    近几篇ElasticSearch系列: 1.阿里云服务器Linux系统安装配置ElasticSearch搜索引擎 2.Linux系统中ElasticSearch搜索引擎安装配置Head插件 3.Ela ...

  2. Python 更换国内pip源

    pip国内的一些镜像: 阿里云 http://mirrors.aliyun.com/pypi/simple/   中国科技大学 https://pypi.mirrors.ustc.edu.cn/sim ...

  3. Qt 独立运行时伴随CMD命令窗口

    用Qt写了一个小软件,在把程序release后,打包分装后,发现程序运行的时候会伴随cmd命令窗口,可把我愁怀了 不过功夫不负有心人,在老师和我网友的帮助下,终于搞完了 CONFIG:指定工程配置和编 ...

  4. Selenium 入门到精通系列:五

    Selenium 入门到精通系列 PS:显式等待.隐式等待.强制等待方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019 ...

  5. Python简要标准库(1)

    sys sys这个模块让你能够访问与Python解释器联系紧密的变量和函数 其中的一些在下表 F argv 命令行参数,包括脚本名称 exit([arg]) 退出当前的程序,可选参数为给定的返回值或者 ...

  6. 211. String Permutation【LintCode by java】

    Description Given two strings, write a method to decide if one is a permutation of the other. Exampl ...

  7. yun rpm

    RPM:RedHat Package Manager的简称,是一种数据库记录的方式的管理机制.当需要安装的软件的依赖软件都已经安装,则继续安装,否则不予安装. 特点:1.已经编译并打包完成2.软件的信 ...

  8. node包管理相关

    切换npm数据源 镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): 1.通过config命令 npm config set registry https ...

  9. Thunder团队第六周 - Scrum会议5

    Scrum会议5 小组名称:Thunder 项目名称:i阅app Scrum Master:翟宇豪 工作照片: 胡佑蓉同学在拍照,所以不在照片内. 参会成员: 王航:http://www.cnblog ...

  10. Crawling is going on - Beta版本测试报告

    [Crawling is going on - Beta版本] 测试报告 文件状态: [] 草稿 [√] 正式发布 [] 正在修改 报告编号: 当前版本: 2.0.2 编写人: 周萱.刘昊岩.居玉皓 ...