poj3678
题目给的太裸,显然2sat;
还是用i表示xi=true(1), i+n表示xi=false(0)
这题唯一要说的是一种情况,当xi必须=true或xi必须=false这种情况下怎么弄
比如这道题出现的 假如条件要求xi or xj=0 那么
除了i+n--->j+n ,j+n--->i+n这两条边外
显然还要xi,xj都必须取false
这种情况我们好像不好用“推导出”的原理建边,
考虑这样的情况1,假如存在路径i+n--->i,但不存在路径i--->i+n
为什么这种情况是有解的,这是因为我们我们可以取i这个状态,这样就成立了,而取i+n这个状态是不成立的
现在我们要求一定只能取i+n这个状态
我们就连边i--->i+n
假如是情况1,加上这条边后,显然无解,符合。
假如i和i+n间都没有路径,显然加了这条边之后,就转化为情况1,这样显然只能取i+n这个状态
假如原来无解,加了边之后现在当然也无解
所以,对于xi,not xi,我们一定要取xi的话
我们就连边xi<--- not xi,这样就可以了
type node=record
next,point:longint;
end; var edge:array[..] of node;
v,f:array[..] of boolean;
be,st,dfn,low,p:array[..] of longint;
sum,h,t,a,b,c,i,n,m,len:longint;
s:string; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure add(x,y:longint);
begin
inc(len);
edge[len].point:=y;
edge[len].next:=p[x];
p[x]:=len;
end; procedure tarjan(x:longint);
var i,y:longint;
begin
inc(h);
dfn[x]:=h;
low[x]:=h;
inc(t);
st[t]:=x;
f[x]:=true;
v[x]:=true;
i:=p[x];
while i<>- do
begin
y:=edge[i].point;
if not v[y] then
begin
tarjan(y);
low[x]:=min(low[x],low[y]);
end
else if f[y] then low[x]:=min(low[x],low[y]);
i:=edge[i].next;
end;
if dfn[x]=low[x] then
begin
inc(sum);
while st[t+]<>x do
begin
y:=st[t];
f[y]:=false;
be[y]:=sum;
dec(t);
end;
end;
end; begin
fillchar(p,sizeof(p),);
readln(n,m);
for i:= to m do
begin
read(a,b,c);
inc(a);
inc(b);
readln(s);
if s=' AND' then
begin
if c= then
begin
add(a,b+n);
add(b,a+n);
end
else begin
add(a,b);
add(b,a);
add(a+n,a);
add(b+n,b);
end;
end
else if s=' OR' then
begin
if c= then
begin
add(a+n,b+n);
add(b+n,a+n);
add(a,a+n);
add(b,b+n);
end
else begin
add(a+n,b);
add(b+n,a);
end;
end
else if s=' XOR' then
begin
if c= then
begin
add(a+n,b+n);
add(b+n,a+n);
add(a,b);
add(b,a);
end
else begin
add(a+n,b);
add(a,b+n);
add(b+n,a);
add(b,a+n);
end;
end;
end;
for i:= to *n do
if not v[i] then
begin
h:=;
t:=;
tarjan(i);
end; for i:= to n do
if be[i]=be[i+n] then
begin
writeln('NO');
halt;
end;
writeln('YES');
end.
poj3678的更多相关文章
- hdu 4421 和poj3678类似二级制操作(2-sat问题)
/* 题意:还是二进制异或,和poj3678类似 建边和poj3678一样 */ #include<stdio.h> #include<string.h> #include&l ...
- poj3678 Katu Puzzle 2-SAT
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6714 Accepted: 2472 Descr ...
- 2-sat(and,or,xor)poj3678
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7949 Accepted: 2914 Descr ...
- POJ-3678 Katu Puzzle 2sat
题目链接:http://poj.org/problem?id=3678 分别对and,or,xor推出相对应的逻辑关系: 逻辑关系 1 0 A and B A'->A,B'->B ...
- POJ3678【错误总会让自己有收获的】
首先我是的确确定了LRJ那个代码也是判断一个点的两种状态是否在一个连通分量内. 关于自己做的,自己又确定了一些,让自己那样先,比如说对于 3 6 1 AND这样3 6都已经确定的点,自己用 ...
- poj3678(two-sat)
传送门:Katu Puzzl 题意:n个点,点的取值可以是0或者1.m条边,有权值,有运算方式(并,或,异或),要求和这条边相连的两个点经过边上的运算后的结果是边的权值.问你有没有可能把每个点赋值满足 ...
- Poj3678:Katu Puzzle
大概题意 有\(n\)个数,可以为\(0/1\),给\(m\)个条件,表示某两个数经过\(or, and, xor\)后的数是多少 判断是否有解 Sol \(2-SAT\)判定 建图 # includ ...
- POJ3678 Katu Puzzle
原题链接 \(2-SAT\)模板题. 将\(AND,OR,XOR\)转换成\(2-SAT\)的命题形式连边,用\(tarjan\)求强连通分量并检验即可. #include<cstdio> ...
- POJ3678:Katu Puzzle——题解
http://poj.org/problem?id=3678 总觉得这题比例题简单. 设a为x取0的点,a+n为x取1的点. 我们还是定义a到b表示取a必须取b. 那么我们有: 当AND: 1.当c= ...
随机推荐
- OpenJudge/Poj 1083 Moving Tables
1.链接地址: http://poj.org/problem?id=1083 http://bailian.openjudge.cn/practice/1083/ 2.题目: 总时间限制: 1000m ...
- 开发日志系列:一个表单页面的呈现与提交(一)——JSON的操作
JSON操作 引子 最近在做一个表单页面,大概是这个样子的 这里打算用一个JSON存储所有的信息,我们可以理解为,所有东西都存在一个字符串里面.方便,快捷,易读,数据库操作也方便了.甚至,可以将很多不 ...
- ThreadPoolExecutor 线程池的实现
ThreadPoolExecutor继承自 AbstractExecutorService.AbstractExecutorService实现了 ExecutorService 接口. 顾名思义,线程 ...
- 51nod1046快速幂取余
给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = 3. Input 3个正整数A B C,中间用空格分隔.(1 <= A,B,C <= 10^ ...
- Sql Server 判断表或数据库是否存在
发布:thebaby 来源:脚本学堂 [大 中 小] 本文详细介绍了,在sql server中判断数据库或表是否存在的方法,有理论有实例,有需要的朋友可以参考下,一定有帮助的.原文地址:h ...
- javascript cookie 操作
<html> <head> <meta charset="utf-8"> <title>Javascript cookie</ ...
- Linux下18b20温度传感器驱动代码及测试实例
驱动代码: #include <linux/module.h> #include <linux/fs.h> #include <linux/kernel.h> #i ...
- android实现视频图片取缩略图
取缩略图不等同于缩放图片. 缩放图片是保持不失真的情况下缩放处理,并进行平滑处理. 缩略图则不然,允许失真,目的只是取出图片的轮廓. 保存Bitmap图片 private void saveBitma ...
- 8.MVC框架开发(URL路由配置和URL路由传参空值处理)
1.ASP.NET和MVC的路由请求处理 1)ASP.NET的处理 请求---------响应请求(HttpModule)--------处理请求(HttpHandler)--------把请求的资源 ...
- JLOI 2013 卡牌游戏
问题描述: N个人坐成一圈玩游戏.一开始我们把所有玩家按顺时针从1到N编号.首先第一回合是玩家1作为庄家.每个回合庄家都会随机(即按相等的概率)从卡牌堆里选择一张卡片,假设卡片上的数字为X,则庄家首先 ...