poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)
http://poj.org/problem?id=3207
Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 7021 | Accepted: 2604 |
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
- /**
- Status:Accepted Memory:18024K
- Time:219MS Language:G++
- Code Lenght:2100B Author:cj
- */
- #include<iostream>
- #include<stdio.h>
- #include<string.h>
- #include<algorithm>
- #include<stack>
- #define N 1010000 //RE很多次,一个个试出来的
- using namespace std;
- struct Edge
- {
- int next,v;
- }edge[N];
- int a[N],b[N];
- int n,m,edge_cnt;
- int head[N];
- int pre[N],low_link[N],sccno[N],dfs_cnt,scc_cnt;
- stack<int> stk;
- void addEdge(int u,int v)
- {
- edge[edge_cnt].v = v;
- edge[edge_cnt].next = head[u];
- head[u] = edge_cnt++;
- }
- void Tarjan(int u)
- {
- pre[u]=low_link[u] = ++dfs_cnt;
- stk.push(u);
- int i;
- for(i=head[u];i!=-;i=edge[i].next)
- {
- int v = edge[i].v;
- if(!pre[v])
- {
- Tarjan(v);
- low_link[u]=min(low_link[u],low_link[v]);
- }
- else if(!sccno[v])
- {
- low_link[u] = min(low_link[u],pre[v]);
- }
- }
- if(pre[u]==low_link[u])
- {
- scc_cnt++;
- int x;
- do
- {
- x = stk.top();
- stk.pop();
- sccno[x] = scc_cnt;
- }while(x!=u);
- }
- }
- void find_scc()
- {
- int i;
- memset(pre,,sizeof(pre));
- memset(low_link,,sizeof(low_link));
- memset(sccno,,sizeof(sccno));
- dfs_cnt = scc_cnt = ;
- for(i=;i<=*m;i++)
- {
- if(!pre[i]) Tarjan(i);
- }
- }
- int main()
- {
- scanf("%d%d",&n,&m);
- int i;
- for(i=;i<=m;i++)
- {
- scanf("%d%d",&a[i],&b[i]);
- if(a[i]>b[i]) swap(a[i],b[i]);
- }
- int j;
- memset(head,-,sizeof(head));
- edge_cnt = ;
- for(i=;i<=m;i++)
- {
- for(j=;j<=m;j++)
- {
- if((a[i]<a[j]&&b[i]<b[j]&&b[i]>a[j])||(a[i]>a[j]&&b[i]>b[j]&&b[i]<a[j]))
- {
- addEdge(i,j+m);
- addEdge(j,i+m);
- addEdge(i+m,j);
- addEdge(j+m,i);
- }
- }
- }
- find_scc();
- for(i=;i<=m;i++)
- if(sccno[i]==sccno[i+m])
- {
- break;
- }
- if(i<=m) puts("the evil panda is lying again");
- else puts("panda is telling the truth...");
- return ;
- }
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
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)
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,基础)
题意: 有一个环,环上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
POJ 3207 Ikki's Story IV - Panda's Trick liympanda, one of Ikki's friend, likes playing games with I ...
- Ikki's Story IV - Panda's Trick POJ - 3207(水2 - sat 在圈内 还是 在圈外)
题意: 就是一个圈上有n个点,给出m对个点,这m对个点,每一对都有一条边,合理安排这些边在圈内或圈外,能否不相交 解析: 我手残 我手残 我手残 写一下情况 只能是一个在圈外 一个在圈内 即一个1一个 ...
随机推荐
- 一次配置jdk环境变量的感悟
开发java也一年多了,昨日一次偶然的机会,想在dos命令下执行一个程序,发现在 命令行输入 javac Test.java的时候,竟然提示javac不是内部命令, 之后输入 java ,也提示不是内 ...
- 移动端开发的meta标签作用
一.<meta name="viewport" id="viewport" content="width=device-width, initi ...
- 《JavaScript模式》读书笔记
简介 在软件开发过程中,模式是指一个通用问题的解决方案.一个模式不仅仅是一个可以用来复制粘贴的代码解决方案,更多地是提供了一个更好的实践经验.有用的抽象化表示和解决一类问题的模板. 对象有两大类: 本 ...
- Java Concurrency - ReadWriteLock & ReentrantReadWriteLock
锁所提供的最重要的改进之一就是 ReadWriteLock 接口和它的实现类 ReentrantReadWriteLock.这个类提供两把锁,一把用于读操作和一把用于写操作.同一时间可以有多个线程执行 ...
- python遍历目录文件脚本的示例
例子 自己写的一个Python遍历文件脚本,对查到的文件进行特定的处理.没啥技术含量,但是也记录一下吧. 代码如下 复制代码 #!/usr/bin/python# -*- coding: utf-8 ...
- Swift方法
Swift 中的方法是与特定类型(类和结构体)相关的函 数. 实例方法 隶属于某个特定类型(类或结构体)实例函数. class Counter{ var count = 0 funcincrement ...
- PHP学习笔记--入门篇
PHP学习笔记--入门篇 一.Echo语句 1.格式 echo是PHP中的输出语句,可以把字符串输出(字符串用双引号括起来) 如下代码 <?php echo "Hello world! ...
- Android Animation学习笔记
原文地址: http://www.cnblogs.com/feisky/archive/2010/01/11/1644482.html 关于动画的实现,Android提供了Animation,在And ...
- CAF(C++ actor framework)使用随笔(unbecome与keep_behavior用法)
看usermanual(使用随笔一里面有)看到差不多一半的时候,这个keep_behavior与unbeacome的结合引起了我的注意.(这是为什么呢?) 因为它的示例代码写的太简单了!我真的没看太懂 ...
- template_11实参演绎
1,演绎过程匹配类型A(来自实参的类型),参数化类型P(行参参数声明)如果被声明的参数是一个引用声明g(T& )那么P就是所引用类型T:f(T)中P就是所声明的参数类: decay指从数组和函 ...