poj 3678 Katu Puzzle(Two Sat)
题目链接:http://poj.org/problem?id=3678
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std; const int maxn = ; struct Two_Sat
{
int n;
vector<int> G[maxn*];
bool mark[maxn*];
int s[maxn*],cnt; void init(int n)
{
this->n = n;
memset(mark,,sizeof(mark));
for(int i=; i<n*; i++) G[i].clear();
} void add_clause(int u,int v,int flag,char symbol)
{
u = u* + flag;
v = v* + flag;
if(symbol == 'A')
{
if(flag)
{
G[u].push_back(v);
G[v].push_back(u);
G[u^].push_back(u);
G[v^].push_back(v);
}
else
{
G[u^].push_back(v);
G[v^].push_back(u);
}
}
else if(symbol == 'O')
{
if(flag)
{
G[u^].push_back(v);
G[v^].push_back(u);
}
else
{
G[u].push_back(v);
G[v].push_back(u);
G[u^].push_back(u);
G[v^].push_back(v);
}
}
else
{
if(flag)
{
G[u^].push_back(v);
G[v].push_back(u^);
G[v^].push_back(u);
G[u].push_back(v^);
}
else
{
G[u].push_back(v);
G[v].push_back(u);
G[u^].push_back(v^);
G[v^].push_back(u^);
}
}
} bool dfs(int u)
{
if(mark[u^]) return false;
if(mark[u]) return true;
mark[u] = true;
s[cnt++] = u;
for(int i=; i<G[u].size(); i++)
{
if(!dfs(G[u][i])) return false;
}
return true;
} bool solve()
{
for(int i=; i<n*; i+=)
{
if(!mark[i] && !mark[i+])
{
cnt = ;
if(!dfs(i))
{
while(cnt>) mark[s[--cnt]] = false;
if(!dfs(i+)) return false;
}
}
}
return true;
}
}solver; int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int N,M;
while(cin>>N>>M)
{
solver.init(N);
for(int i=; i<=M; i++)
{
int a,b,c;
char s[];
scanf("%d %d %d %s",&a,&b,&c,s);
solver.add_clause(a,b,c,s[]);
}
if(solver.solve()) printf("YES\n");
else printf("NO\n");
}
}
poj 3678 Katu Puzzle(Two Sat)的更多相关文章
- 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)
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)
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6553 Accepted: 2401 Descr ...
- POJ 3678 Katu Puzzle (2-SAT)
Katu Puzzle Time Limit: 1000MS ...
- 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 ...
- POJ 3678 Katu Puzzle 2-SAT 强连通分量 tarjan
http://poj.org/problem?id=3678 给m条连接两个点的边,每条边有一个权值0或1,有一个运算方式and.or或xor,要求和这条边相连的两个点经过边上的运算后的结果是边的权值 ...
- POJ 3678 Katu Puzzle
Description 给出一个关系,包括 And,Xor,Or 问是否存在解. Sol 经典的2-SAT问题. 把每个值看成两个点,一个点代表选 \(0\) ,另一个代表选 \(1\) . 首先来看 ...
- POJ 3678 Katu Puzzle(强连通 法)
题目链接 题意:给出a, b, c 和操作类型 (与或异或),问是否满足所有的式子 主要是建图: 对于 and , c == 1: 说明 a 和 b都是1,那么 0 就不能取, a' -> a ...
随机推荐
- oracle编译 失效对象方式
如果procedure 所使用的表结构发生了改变等其它情况,在相应的xxx_objects表的status字段会变为invalid状态,但是如果在调用时procedure会自动编译,grant失效对象 ...
- windows 远程连接linux服务器
百度搜索“SSH Secure Shell Client” 并下载 2 点击Profiles选择add profiles 并添加profils名称 3 点击Profiles 填写远程linux的ip ...
- 【转载】介绍“Razor”— ASP.NET的一个新视图引擎
最近在做一个项目,用的MVC razor 视图,因为之前没用这个视图做过,于是查阅文档资料,共享一下. https://msdn.microsoft.com/zh-cn/ff849693 内容主要是讲 ...
- free() 是如何释放不同内存区块大小的指针?
最初是在知乎上看到这个问题的C++ delete[] 是如何知道数组大小的?,我也挺好奇,所以就作了一番工作. 申请内存时,指针所指向区块的大小这一信息,其实就记录在该指针的周围看下面这段代码: #i ...
- sql语句select group by order by where一般先后顺序 转载
写的顺序:select ... from... where.... group by... having... order by..执行顺序:from... where...group by... h ...
- postman本地或远程访问不了
问题postman: 问题描述: 1.手动测试过不去http://121.199.54.31:8081/suppliers/Split 2.localhost:8080/microshop-settl ...
- 《玩转shutdown》-linux命令五分钟系列之十三
1 我想立即关机! $shutdown -h now 2 我想立即重启 $shutdown -r now 3 我想在23:30分准时关机 $shutdown -h 23:30 4 我想在15分钟后关机 ...
- 开启/关闭ubuntu防火墙
LInux原始的防火墙工具iptables由于过于繁琐,所以ubuntu系统默认提供了一个基于iptable之上的防火墙工具ufw.而UFW支持图形界面操作,只需在命令行运行ufw命令即能看到一系列的 ...
- Android 简单的FC
直接贴log 01-02 08:17:56.589 I/ActivityManager( 312): Start proc com.android.providers.calendar for con ...
- python 连 mongodb
这几天在学习Python Web开发,于是做准备做一个博客来练练手,当然,只是练手的,博客界有WordPress这样的好玩意儿,何必还自己造车呢?决定使用Tornado这个框架,然后数据库方面决定顺便 ...