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 ...
随机推荐
- webpack的世界
本文也是多次学习webapck积累下来的知识点,一直在云笔记里. webpack的原理 webpack构建流程 从启动webpack构建到输出结果经历了一系列过程,它们是: 解析webpack配置参数 ...
- ansible安装
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 1.配置epel源 wget -O /etc/yum.repos.d ...
- Https访问
Let's Encrypt是很火的一个免费SSL证书发行项目,自动化发行证书,证书有90天的有效期.适合个人使用或者临时使用,不用再忍受自签发证书不受浏览器信赖的提示.去年VPS侦探曾经说过Let's ...
- Linux下yum安装MysqL数据库
1.命令安装mysql # yum install mysql mysql-server mysql-devel -y 最后提示 Complete! 表示安装成功 2.查看是否生成了mysqld服务 ...
- CSS盒模型的深度思考及BFC
本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. 题目:谈一谈你对CSS盒模型的认识 专业的面试,一定会问 CSS 盒模型 ...
- Lua Table转C# Dictionary
因为在游戏公司做web后台开发,经常会涉及到取游戏服务器的数据库里面读写各种操作. 昨天下午,服务器那边让我读一个配置显示到后台,让运营大佬们可以在web后台配置游戏参数. 本来以为很简单个事情,结果 ...
- Pandaboard ES编译bootloader、xloader、内核、以及安卓系统
Building bootloader and kernel Bootloader Startwith building the bootloader. To learn more about the ...
- stm32开发之使用Keil MDK以及标准外设库创建STM32工程
‑6 MDK详细版本信息 ‑8保存路径的选择 ‑9选择芯片型号 ‑10拷贝启动代码选择 ‑11选择 Manage Comoonents ‑12编辑组并添加对应文件 ‑13工程管理文件列表 ‑14选择进 ...
- 使用串口下载vxworks映象的方法
使用串口下载vxworks映象的方法 由于坛子里这方面的可行性文章比较少,不时有一些网友在询问这方面的问题,再加上通过这种方法可以调试网络驱动,所以我花了一点时间把整个下载过程试了一下. 1.配置co ...
- freemarker写select组件报错总结(六)
1.错误描述 六月 26, 2014 10:53:26 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...