传送门:Ikki's Story IV - Panda's Trick

题意:给定一个圆,圆上一些点。两点一线。现给出一些线,这些线可以在圆内连起来,也可以在圆外。问有没有可能所有的线画完且不出现相交。

分析:对于每条线,要么在圆外,要么在圆内,且不可同时满足,只能两者取一,判断这M条线是否合法,也就是M条线不冲突,这就是典型的2-sat问题了。

将每条线在圆内当成一点i,在圆外当成一点i',对于两条线,如果在园内同时在圆内,那么必定也不能同时在园外,则有边(i, j') 、(j ,i')、(i',j)、(j' ,i)。

这题由于不用输出方案,直接tarjan缩点后判断[i,i']是否属于一个强连通内即可。

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 100000000
#define inf 0x3f3f3f3f
#define eps 1e-6
#define N 2010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
struct edge
{
int v,next;
edge(){}
edge(int v,int next):v(v),next(next){}
}e[N*N/];
struct node
{
int l,r;
}s[N];
int n,m,scc,step,top,tot;
int head[N],dfn[N],low[N],belong[N],Stack[N];
bool instack[N];
void init()
{
tot=;step=;scc=;top=;
FILL(head,-);FILL(dfn,);
FILL(low,);FILL(instack,false);
}
void addedge(int u,int v)
{
e[tot]=edge(v,head[u]);
head[u]=tot++;
}
void tarjan(int u)
{
int v;
dfn[u]=low[u]=++step;
Stack[top++]=u;
instack[u]=true;
for(int i=head[u];~i;i=e[i].next)
{
v=e[i].v;
if(!dfn[v])
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(instack[v])
{
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u])
{
scc++;
do
{
v=Stack[--top];
instack[v]=false;
belong[v]=scc;
}while(v!=u);
}
}
bool ok(int i,int j)
{
int x1=s[i].l,y1=s[i].r;
int x2=s[j].l,y2=s[j].r;
if( x2>x1&&x2<y1 ){
if( y2>=y1 ) return true;
if( y2<=x1 ) return true;
}
if( y2>x1&&y2<y1 ){
if( x2>=y1 ) return true;
if( x2<=x1 ) return true;
}
return false;
}
void solve()
{
for(int i=;i<=*m;i++)
if(!dfn[i])tarjan(i);
bool flag=true;
for(int i=;i<=m;i++)
{
if(belong[i]==belong[i+m])
{
flag=false;
break;
}
}
if(flag)puts("panda is telling the truth...");
else puts("the evil panda is lying again");
}
int main()
{
int a,b;
while(scanf("%d%d",&n,&m)>)
{
init();
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
a++;b++;
s[i].l=min(a,b);
s[i].r=max(a,b);
}
for(int i=;i<=m;i++)
for(int j=i+;j<=m;j++)
if(ok(i,j))
{
addedge(i,j+m);
addedge(j+m,i);
addedge(j,i+m);
addedge(i+m,j);
}
solve();
}
}

poj3207(two-sat)的更多相关文章

  1. 学习笔记(two sat)

    关于two sat算法 两篇很好的论文由对称性解2-SAT问题(伍昱), 赵爽 2-sat解法浅析(pdf). 一些题目的题解 poj 3207 poj 3678 poj 3683 poj 3648 ...

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

  3. Katu Puzzle POJ - 3678 (2 - sat)

    有N个变量X1X1~XNXN,每个变量的可能取值为0或1. 给定M个算式,每个算式形如 XaopXb=cXaopXb=c,其中 a,b 是变量编号,c 是数字0或1,op 是 and,or,xor 三 ...

  4. LA 3211 飞机调度(2—SAT)

    https://vjudge.net/problem/UVALive-3211 题意: 有n架飞机需要着陆,每架飞机都可以选择“早着陆”和“晚着陆”两种方式之一,且必须选择一种,第i架飞机的早着陆时间 ...

  5. spring定时任务详解(@Scheduled注解)( 转 李秀才的博客 )

    在springMVC里使用spring的定时任务非常的简单,如下: (一)在xml里加入task的命名空间 xmlns:task="http://www.springframework.or ...

  6. MongoDB 聚合管道(Aggregation Pipeline)

    管道概念 POSIX多线程的使用方式中, 有一种很重要的方式-----流水线(亦称为"管道")方式,"数据元素"流串行地被一组线程按顺序执行.它的使用架构可参考 ...

  7. mysql触发器,答题记录表同步教学跟踪(用户列表)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVQAAAOOCAIAAABgEw4AAAAgAElEQVR4nOy92VcT27r/zX+xLtflvt

  8. Linux版Matlab R2015b的bug——脚本运行的陷阱(未解决)

    0 系统+软件版本 系统:CentOS 6.7 x64, 内核 2.6.32-573.el6.x86_64软件:Matlab R2015b(包括威锋网和东北大学ipv6下载的资源,都测试过) 1 脚本 ...

  9. Quartz.net(调度框架) 使用Mysql作为存储

    最近公司的做的项目中涉及到配置任务地址然后按照配置去目标地址提取相关的数据,所以今天上午在Internet上查看有关定时任务(调度任务)的相关信息,筛选半天然后查找到Quartz.net. Quart ...

  10. mysql 函数编程大全(持续更新)

    insert ignore insert ignore表示,如果中已经存在相同的记录,则忽略当前新数据 如果您使用一个例如“SET col_name = col_name + 1”的赋值,则对位于右侧 ...

随机推荐

  1. Linux内核源代码解析之——sock's buffer参数

    本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/11539695 关于socket与sock的关系再简单 ...

  2. 【模式识别】Boosting

    Boosting简单介绍 分类中通常使用将多个弱分类器组合成强分类器进行分类的方法,统称为集成分类方法(Ensemble Method).比較简单的如在Boosting之前出现Bagging的方法,首 ...

  3. Java ArrayList add(int index, E element) example

    Simple add() method is used for adding an element at the end of the list however there is another va ...

  4. Fibinary Numbers

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30506#problem/V 题意:从右向左,每一个位数,分别表示一个fibonacci数 ...

  5. python中文注释及输出出错

    今天开始接触python,中文报错,你懂的,不细说. 网上很多类似的解决方案,有不是很明确,例如:http://blog.csdn.net/chen861201/article/details/770 ...

  6. hdu 2871 Memory Control(伸展树splay tree)

    hdu 2871 Memory Control 题意:就是对一个区间的四种操作,NEW x,占据最左边的连续的x个单元,Free x 把x单元所占的连续区间清空 , Get x 把第x次占据的区间输出 ...

  7. js验证日期

    寻寻觅觅,Web开发里,对日期的验证太多了,网上好多是用正则表达式来验证,但是这种验证也只能验证格式,没办法验证有效性,比如平年(2月28天)和闰年(2月29天).平时用得多,以前经常用一次写一次,腻 ...

  8. 基于visual Studio2013解决面试题之0301累加

     题目

  9. boost.asio系列——io_service

    IO模型 io_service对象是asio框架中的调度器,所有异步io事件都是通过它来分发处理的(io对象的构造函数中都需要传入一个io_service对象). asio::io_service i ...

  10. jeecg智能开发平台参与-2013年度中国优秀开源项目评比

    JEECG正在参与<2013年度中国十大优秀开源项目> 评比,如果大家觉得JEECG还不错, 请投出你宝贵的一票,给我们以支持吧!!! [目前排名第8位] https://code.csd ...