大概题意

有\(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. python学习:递归列出目录里的文件

    #!/usr/bin/python   import os import sys   def print_files(path):     lsdir = os.listdir(path)     d ...

  2. 隱藏在素數規律中的Pi -- BZOJ1041解題報告

    退役狗在刷程書的過程中看到了一個有趣的視頻, 講解了一個有趣的問題. 在網上隨便搜索了一下居然還真的找到了一道以它爲背景的OI題目, BZOJ1041. 下面的內容會首先回顧一下視頻所討論的知識, 有 ...

  3. Taurus.MVC 2.2.3.4 :WebAPI 实现权限控制认证(及功能增强说明)

    前言: 前两天,当我还在老家收拾行旅,准备回广州,为IT连的创业再战365天时, 有网友扣上问:Taurus.MVC中如何实现认证和权限控制,最好能做个小例子. 我一不小心回了句:等回广州我再写篇文章 ...

  4. WebView性能优化--独立进程

    Android允许一个app同时存在多个进程,可以根据需要把不同的模块放到不同进程中处理. 一.WebView独立进程的好处 1.有效增大App的运存,减少由webview引起的内存泄露对主进程内存的 ...

  5. .NET平台开源项目速览(20)Newlife.Core中简单灵活的配置文件

    记得5年前开始拼命翻读X组件的源码,特别是XCode,但对Newlife.Core 的东西了解很少,最多只是会用用,而且用到的只是九牛一毛.里面好用的东西太多了. 最近一年时间,零零散散又学了很多,也 ...

  6. CentOS7上安装并配置Nginx、PHP、MySql

    一.Nginx 1.安装nginx yum install nginx 2.启动nginx systemctl start nginx 除了systemctl start nginx之外,常用的相关命 ...

  7. 如何使用 VS生成动态库?

    如何使用 VS生成动态库? //.cpp 文件默认定义了 __cplusplus 宏 #ifdef __cplusplus extern "C"{ #endif xxx #ifde ...

  8. POJ - 1984 Navigation Nightmare 种类并查集

    思路:记录每个点与其根结点的横向距离和纵向距离,当知道其父节点与根结点的关系,很容易推出当前节点与根结点的关系: 直接相加即可. int p = a[x].par; a[x].dx += a[p].d ...

  9. hdu 2018递推

    第n月的牛的数量由第n-1个月的老牛加上n-1个月新生的小牛,得到公式F(n)=F(n-1)+F(n-3) AC代码: #include<cstdio> const int maxn=55 ...

  10. Subsequence Count (线段树)

    Time Limit: 1000 ms   Memory Limit: 256 MB Description 给定一个01串 $S_{1 \cdots n}$ 和 $Q$ 个操作. 操作有两种类型: ...