POJ 3678 Katu Puzzle
来源:互联网 发布:淘宝起名靠谱吗 编辑:程序博客网 时间:2024/06/15 18:30
大意不再赘述。
思路:有几个表达式我们可以假设c的值为0或者1,然后去推相互之间有矛盾的点,连边时,我们将点拆为2个,一个表示0,一个表示1,Tarjan时就需要循环到2*n啦,有些表达式重复了,比如异或所有的重复了,所以不需要再增加边。
a AND b == 1 (a,b同时为1) a->b, b->a, ~a-->a, ~b-->b;
a AND b == 0 (a,b不同时为1) a-->~b, b-->~a;
a OR b == 1 (a,b不同时为0) ~a-->b, ~b-->a;
a OR b == 0 (a,b同时为0) ~a->~b, ~b->~a, a-->~a, b-->~b;
a XOR b == 1 (a,b不相同为1) a->~b, b->~a, ~a->b, ~b->a;
a XOR b == 0 (a,b相同为0) a->b, b->a, ~a->~b, ~b->~a;
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <string>#include <cstdlib>using namespace std;const int MAXN = 2020;const int MAXM = 1000100;struct Edge{ int u, v, next;}edge[MAXM];int first[MAXN], stack[MAXN], ins[MAXN], low[MAXN], dfn[MAXN];int belong[MAXM];int ind[MAXN], outd[MAXN];int cnt;int n, m;int scnt, top, tot;void init(){ cnt = 0; scnt = top = tot = 0; memset(first, -1, sizeof(first)); memset(ins, 0, sizeof(ins)); memset(dfn, 0, sizeof(dfn));}void read_graph(int u, int v){ edge[cnt].v = v; edge[cnt].next = first[u], first[u] = cnt++;}void dfs(int u){ int v; low[u] = dfn[u] = ++tot; stack[top++] = u; ins[u] = 1; for(int e = first[u]; e != -1; e = edge[e].next) { v = edge[e].v; if(!dfn[v]) { dfs(v); low[u] = min(low[u], low[v]); } else if(ins[v]) { low[u] = min(low[u], dfn[v]); } } if(low[u] == dfn[u]) { scnt++; do { v = stack[--top]; belong[v] = scnt; ins[v] = 0; }while(u != v); }}void Tarjan(){ for(int v = 0; v < 2*n; v++) if(!dfn[v]) dfs(v);}void read_case(){init();while(m--){int x, y, c;char str[5];scanf("%d%d%d%s", &x, &y, &c, str);if(str[0] == 'A') //拆点为2*x, 2*x+1,前者表示~a,后者表示a {if(c){read_graph(2*x, 2*x+1);read_graph(2*y, 2*y+1);}else{read_graph(2*x+1, 2*y);read_graph(2*y+1, 2*x);}}else if(str[0] == 'O'){if(c){read_graph(2*x, 2*y+1);read_graph(2*y, 2*x+1);}else{read_graph(2*x+1, 2*x);read_graph(2*y+1, 2*y);}}}}void solve(){ read_case(); Tarjan(); for(int i = 0; i < 2*n; i += 2) { if(belong[i] == belong[i+1]) { printf("NO\n"); return ; } } printf("YES\n"); }int main(){ while(~scanf("%d%d", &n, &m)) { solve(); } return 0;}
- POJ 3678 Katu Puzzle
- poj 3678 Katu Puzzle
- poj 3678 Katu Puzzle
- POJ 3678 Katu Puzzle
- POJ 3678 Katu Puzzle
- poj 3678 Katu Puzzle
- POJ 3678 Katu Puzzle
- POJ 3678 Katu Puzzle (2-SAT)
- POJ 3678 Katu Puzzle(2-SAT判断)
- poj 3678 Katu Puzzle 2-SAT
- 2-sat->poj 3678 Katu Puzzle
- poj 3678 Katu Puzzle (2-sat)
- POJ 3678 Katu Puzzle(2-SAT)
- poj 3678 2-SAT (Katu Puzzle)
- 【POJ】3678 Katu Puzzle 2-sat
- [2-SAT] poj 3678 Katu Puzzle
- POJ 3678 Katu Puzzle(2-sat)
- POJ 3678 Katu Puzzle(2-sat)
- Spring读书笔记-----Spring核心机制:依赖注入 .
- 我见过最好的vsftpd配置教程
- setContentView(R.layout.activity_);ui->setupUi(this);
- 全备份、增量备份与差量备份
- Windows核心编程学习笔记(22)--Windows线程池
- POJ 3678 Katu Puzzle
- IOS openURL 运行其他的应用程序
- Spring 读书笔记-----Spring容器(一) .
- JSP自定义标签---->张国亮总结第一季
- objective-c笔试题
- WebClient修改远程文件时:“远程服务器返回错误: (501) 未实现”的错误
- OPC协议见解
- 在线的C/C++参考网站
- PHP安装eAccelerator