Poj3678:Katu Puzzle
大概题意
有\(n\)个数,可以为\(0/1\),给\(m\)个条件,表示某两个数经过\(or, and, xor\)后的数是多少
判断是否有解
Sol
\(2-SAT\)判定
建图
# include <iostream>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <math.h>
# include <algorithm>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(2005);
const int __(4e6 + 5);
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n, m, first[_], cnt, num;
int S[_], vis[_], dfn[_], low[_], Index, col[_];
struct Edge{
int to, next;
} edge[__];
IL void Add(RG int u, RG int v){
edge[cnt] = (Edge){v, first[u]}; first[u] = cnt++;
}
IL void Tarjan(RG int u){
vis[u] = 1, dfn[u] = low[u] = ++Index, S[++S[0]] = u;
for(RG int e = first[u]; e != -1; e = edge[e].next){
RG int v = edge[e].to;
if(!dfn[v]) Tarjan(v), low[u] = min(low[u], low[v]);
else if(vis[v]) low[u] = min(low[u], dfn[v]);
}
if(dfn[u] != low[u]) return;
RG int v = S[S[0]--]; col[v] = ++num, vis[v] = 0;
while(v != u) v = S[S[0]--], col[v] = num, vis[v] = 0;
}
int main(RG int argc, RG char* argv[]){
Fill(first, -1), n = Input(), m = Input();
for(RG int i = 1; i <= m; ++i){
RG int u = Input() + 1, v = Input() + 1, w = Input();
RG char op; scanf(" %c", &op);
if(op == 'A'){
if(w) Add(u, v), Add(v, u), Add(u + n, u), Add(v + n, v);
else Add(u, v + n), Add(v, u + n);
}
else if(op == 'O'){
if(w) Add(u + n, v), Add(v + n, u);
else Add(u, u + n), Add(v, v + n), Add(u + n, v + n), Add(v + n, u + n);
}
else{
if(w) Add(u, v + n), Add(v, u + n), Add(u + n, v), Add(v + n, u);
else Add(u, v), Add(v, u), Add(u + n, v + n), Add(v + n, u + n);
}
}
for(RG int i = 1, tmp = n << 1; i <= tmp; ++i)
if(!dfn[i]) Tarjan(i);
for(RG int i = 1; i <= n; ++i)
if(col[i] == col[i + n]) return puts("NO"), 0;
return puts("YES"), 0;
}
Poj3678:Katu Puzzle的更多相关文章
- POJ3678:Katu Puzzle——题解
http://poj.org/problem?id=3678 总觉得这题比例题简单. 设a为x取0的点,a+n为x取1的点. 我们还是定义a到b表示取a必须取b. 那么我们有: 当AND: 1.当c= ...
- poj3678 Katu Puzzle 2-SAT
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6714 Accepted: 2472 Descr ...
- 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 ...
- 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) - 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,合取范式大集合)
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 ...
- 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 建图入门
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
随机推荐
- js小技巧:数组去重
JavaScript 数组中去除重复的数据 var arr = [1, 2, 2, 3, '1', null, 'a', 'b', 'a']; var t = {}; var result = arr ...
- [Python Study Notes]文件操作
文件操作 对文件操作流程 打开文件,可添加filepath打开某绝对路径下的文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 # The_author = 'liu66' # -* ...
- Java开发API文档资源
<netty> http://netty.io/4.1/api/index.html < Spring FrameWork > 1 http://spring.io/ 2 ...
- 箱型图boxplot函数的使用
主要参数: medlwd:设置中位线宽度 whiskcol:设置虚线颜色 staplecol:设置顶端颜色 outcol:离群值颜色 相应的具体位置: outline=FALSE:去除离群值 outp ...
- django-高级视图和url配置
高级视图和url配置 一.URLconf技巧 1.流线型化函数导入 对于配置url,我们可以使用以下几种方式: (1)引入view中的函数 from firstSite.view import cur ...
- REST&RESTFUL
REST(表征性状态传输,Representational State Transfer)指的是一组架构约束条件和原则.是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格 ...
- java url demo
// File Name : URLDemo.java import java.net.*; import java.io.*; public class URLDemo { public stati ...
- 《设计模式之禅》--设计模式大PK
创建类模式包括工厂方法模式.建造者模式.抽象工厂模式.单例模式和原型模式. 其中单例模式要保持在内存中只有一个对象,原型模式是要求通过复制的方式产生一个新的对象. [工厂方法(抽象工厂) VS 建造者 ...
- 一文解决python模块导入
python 模块导入 原理 查找是按照 sys.path 中的路径挨个扫描.若都不存在则提示error. sys.path路径第一个是当前运行脚本所在的目录,其后是PYTHONPATH(一般若步专门 ...
- TI Davinci DM6446开发攻略——根文件系统的裁剪和移植
一.补充文件系统知识 Linux根文件系统是存放tool软件.lib文件.script(脚本).配置文件.其他特殊文件.自己开发的应用程序的地方.嵌入式linux的根文件系统rootfs就像windo ...