poj--3207--Ikki's Story IV - Panda's Trick(2-sat)
Time Limit: 1000MS | Memory Limit: 131072KB | 64bit IO Format: %I64d & %I64u |
Description
liympanda, one of Ikki’s friend, likes playing games with Ikki. Today after minesweeping with Ikki and winning so many times, he is tired of such easy games and wants to play another game with Ikki.
liympanda has a magic circle and he puts it on a plane, there are n points on its boundary in circular border: 0, 1, 2, …,
n − 1. Evil panda claims that he is connecting m pairs of points. To connect two points, liympanda either places the link entirely inside the circle or entirely outside the circle. Now liympanda tells Ikki no two links touch inside/outside the circle,
except on the boundary. He wants Ikki to figure out whether this is possible…
Despaired at the minesweeping game just played, Ikki is totally at a loss, so he decides to write a program to help him.
Input
The input contains exactly one test case.
In the test case there will be a line consisting of of two integers: n and
m (n ≤ 1,000, m ≤ 500). The following m lines each contain two integers
ai and bi, which denote the endpoints of the
ith wire. Every point will have at most one link.
Output
Output a line, either “panda is telling the truth...
” or “the evil panda is lying again
”.
Sample Input
4 2
0 1
3 2
Sample Output
panda is telling the truth...
Source
#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
#define MAX 100000+10
int low[MAX],dfn[MAX];
int sccno[MAX];
int scc_cnt,dfs_clock,cnt;
bool Instack[MAX];
int m,n,num1[MAX],num2[MAX];
vector<int>G[MAX];
stack<int>s;
struct node
{
int u,v;
int next;
}edge[MAX*2];
void init()
{
for(int i=1;i<=3*m;i++)
G[i].clear(); }
bool judge(int a, int b, int c, int d)
{
return (c > a && b > c && d > b) || (a > c && d > a && b > d);
}
void getmap()
{
for(int i=1;i<=m;i++)
scanf("%d%d",&edge[i].u,&edge[i].v);
for(int i=1;i<=m;i++)
{
for(int j=1;j<i;j++)
{//如果会相交的话
if(judge(edge[i].u,edge[i].v,edge[j].u,edge[j].v))
{
G[i+2*m].push_back(j+m);//i边j边在里在外,四种情况
G[i+m].push_back(j+2*m);
G[j+m].push_back(i+2*m);
G[j+2*m].push_back(i+m);
}
}
}
}
void tarjan(int u,int fa)
{
int v;
low[u]=dfn[u]=++dfs_clock;
s.push(u);
Instack[u]=true;
for(int i=0;i<G[u].size();i++)
{
v=G[u][i];
if(!dfn[v])
{
tarjan(v,u);
low[u]=min(low[v],low[u]);
}
else if(Instack[v])
low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u])
{
++scc_cnt;
for(;;)
{
v=s.top();
s.pop();
Instack[v]=false;
sccno[v]=scc_cnt;
if(v==u) break;
}
}
}
void find(int l,int r)
{
memset(Instack,false,sizeof(Instack));
memset(sccno,0,sizeof(sccno));
memset(dfn,0,sizeof(dfn));
memset(low,0,sizeof(low));
scc_cnt=dfs_clock=0;
for(int i=l;i<=r;i++)
if(!dfn[i])
tarjan(i,-1);
}
void solve()
{
int flog=1;
for(int i=1;i<=m;i++)
{
if(sccno[i+m]==sccno[i+2*m])
{
flog=0;
printf("the evil panda is lying again\n");
break;
}
}
if(flog)
printf("panda is telling the truth...\n");
}
int main()
{
scanf("%d%d",&n,&m);
init();
getmap();
find(1,3*n);
solve();
return 0;
}
poj--3207--Ikki's Story IV - Panda's Trick(2-sat)的更多相关文章
- POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题)
POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题) Description liympanda, one of Ikki's friend, likes ...
- POJ 3207 Ikki's Story IV - Panda's Trick (2-sat)
Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 6691 ...
- poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)
http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 13 ...
- POJ 3207 Ikki's Story IV - Panda's Trick
Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 7296 ...
- POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT,基础)
题意: 有一个环,环上n个点,现在在m个点对之间连一条线,线可以往圆外面绕,也可以往里面绕,问是否必定会相交? 思路: 根据所给的m条边可知,假设给的是a-b,那么a-b要么得绕环外,要么只能在环内, ...
- poj 3207 Ikki's Story IV - Panda's Trick【2-SAT+tarjan】
注意到相交的点对一定要一里一外,这样就变成了2-SAT模型 然后我建边的时候石乐志,实际上不需要考虑这个点对的边是正着连还是反着连,因为不管怎么连,能相交的总会相交,所以直接判相交即可 然后tarja ...
- POJ 3207 Ikki's Story IV - Panda's Trick 2-sat模板题
题意: 平面上,一个圆,圆的边上按顺时针放着n个点.现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接.给你的信息中,每个点最多只会连接的一条边.问能不能连接这m条边,使这 ...
- 【POJ】3207 Ikki's Story IV - Panda's Trick
http://poj.org/problem?id=3207 题意:一个圆上顺时针依次排列着标号为1-n的点,这些点之间共有m条边相连,每两个点只能在圆内或者圆外连边.问是否存在这些边不相交的方案.( ...
- 【poj3207】Ikki's Story IV - Panda's Trick(2-sat)
传送门 题意: 给出一个圆,圆上有\(n\)个点,依次为\(0,1,\cdots,n-1\). 现在要连接\(m\)对点,每次连接时可以直接从里面连,也可以从外面连. 最后问,连完这\(m\)对点后, ...
- 【POJ3207】Ikki's Story IV - Panda's Trick
POJ 3207 Ikki's Story IV - Panda's Trick liympanda, one of Ikki's friend, likes playing games with I ...
随机推荐
- B - Expression
Problem description Petya studies in a school and he adores Maths. His class has been studying arith ...
- 关于iscroll.js插件的使用
iscroll 作用: 可以让区域滚动效果好看一些 使用: 1. html结构 外面必须包一层盒子,切内部的元素要尽量简单,不然会影响滚动效果 <div id="wrapper&quo ...
- DeepMind用ReinforcementLearning玩游戏
原文 : http://dataunion.org/?p=639 1.引言 说到机器学习最酷的分支,非Deep learning和Reinforcement learning莫属(以下分别简称DL和 ...
- 读书笔记「Python编程:从入门到实践」_2.变量和简单数据类型
做了大半年RPA了,用的工具是Kapow. 工作没有那么忙,不想就这么荒废着,想学点什么.就Python吧. 为期三个月,希望能坚持下来. 2.1 变量的命名和使用 变量名只能包含字母.数字和下划线. ...
- css3实现动画滚动条
先给大家一张效果图,看似简单,其实实现起来....那也是非常简单的~简单又实用 黑框里面的字体会自动滚动,形成滚动条,可以用于展示和提示,首先我们先要在body里面写上自己想要的文字,比如我想写:感觉 ...
- (转)RabbitMQ学习之集群部署
http://blog.csdn.net/zhu_tianwei/article/details/40931971 我们先搭建一个普通集群模式,在这个模式基础上再配置镜像模式实现高可用,Rabbit集 ...
- jQuery,您可以实现元素的淡入淡出效果。
fadeIn() fadeOut() fadeToggle() fadeTo() jQuery fadeIn() 用于淡入已隐藏的元素 $("button").click(func ...
- 配置H3C交换机ftp服务
配置H3C交换机ftp服务,用于与交换机进行文件上传.下载,常用于更新程序上传及配置备份文件下载. 准备工作:三层设备(路由器.三层交换机等)至少一个接口配置IP,二层交换机需配置一个处于UP状态的v ...
- kali2018.2安装配置OpenVAS-9及错误处置
1 配置环境 1)虚拟机环境:VMware® Workstation 14 Pro(版本号:14.1.2 build-8497320),如图1. 图1 虚拟机版本信息 2)kali镜像 Kali201 ...
- Jmeter中使用CSV Data Set Config
A