大概题意

有\(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的更多相关文章

  1. POJ3678:Katu Puzzle——题解

    http://poj.org/problem?id=3678 总觉得这题比例题简单. 设a为x取0的点,a+n为x取1的点. 我们还是定义a到b表示取a必须取b. 那么我们有: 当AND: 1.当c= ...

  2. poj3678 Katu Puzzle 2-SAT

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

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

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

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

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

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

  7. POJ 3678 Katu Puzzle (2-SAT)

                                                                         Katu Puzzle Time Limit: 1000MS ...

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

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

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

随机推荐

  1. markdown语法探究

    \[\sum_{i=1}^n a_i=0\] \[f(x_1,x_x,\ldots,x_n) = x_1^2 + x_2^2 + \cdots + x_n^2 \] \[\sum^{j-1}_{k=0 ...

  2. PHP的 first day of 和 last day of

    话不多说,先上代码(当前是2017年6月2日) echo date("Y-m-d", strtotime("2017-02 first day of")).'& ...

  3. cocos2d-x中处理touch事件

    在cocos2d-x中, touch事件分为两种:一种是单点事件, 另一种是多点事件. 单点事件对应的代理方法是: virtual bool ccTouchBegan(CCTouch *pTouch, ...

  4. Python基础——字符串

    Python版本:3.6.2  操作系统:Windows  作者:SmallWZQ 在Python中,字符串也是一种数据类型.相比其它数据类型,字符串算是比较复杂的.为何呢?因为字符串不仅包含英文字母 ...

  5. day1(变量、常量、注释、用户输入、数据类型)

    一.变量 name = "SmallNine" 等号前面是变量名(标识符),等号后面是变量值 变量的主要作用:就是把程序运算的中间结果临时存到内存里,已备后面的代码继续调用. 变量 ...

  6. 【转载】一行代码加载网络图片到ImageView——Android Picasso

    原文链接:一句代码加载网络图片到ImageView——Android Picasso  注意:此处使用下面代码需要先配置一下gradle,下载所需包. 具体操作如下图: compile 'com.sq ...

  7. LVS-DR之VIP、DIP跨网段实例

    在日常应用环境中,我们会遇到这样一种lvs部署环境,所有的dr以及的rs server都在一个局域网环境中,但只有一个公网ip,而又需要将应用发布到internet上,都知道lvs的最好的模式就是所有 ...

  8. linux nginx常见问题及优化,压力测试,tomcat服务器优化

    nginx常见问题 nginx优化全局配置优化[root@web2 nginx]# vim conf/nginx.confuser nobody;worker_processes 1;(与cpu核心数 ...

  9. 简述在javascript和jquery中cookie的使用

    html <body onload="cookieJar()"></body> javascript <script href="../st ...

  10. SQL 脚本持续收集...

    1.复制表 ---sqlserver (包括表结构和表数据) SELECT * INTO TABEL_NEW FROM TABLE_OLD---sqlserver(只复制表结构)CREATE TABL ...