Ikki's Story IV - Panda's Trick
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 7296   Accepted: 2705

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

 
   2-sat ,点为线段。
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#pragma comment(linker, "/STACK:10240000000000,10240000000000")
using namespace std;
typedef long long LL ;
const int Max_N= ;
const int Max_M= ;
int id ;
int vec[Max_N] ,mystack[Max_N] ,top;
int low[Max_N] ,dfn[Max_N] ,idx ,num ;
bool instack[Max_N] ;
int belong[Max_N] ; //belong[i] ,i为哪个联通分量
//int sum[Max_N] ; //缩点后每个联通分量中点的个数
struct Edge{
int v ;
int next ;
};
Edge edge[Max_M] ;
inline void add_edge(int u,int v){
edge[id].v=v ;
edge[id].next=vec[u] ;
vec[u]=id++ ;
}
void tarjan(int u){
low[u]=dfn[u]=idx++ ;
mystack[++top]=u ;
instack[u]= ;
for(int e=vec[u];e!=-;e=edge[e].next){
int v=edge[e].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(low[u]==dfn[u]){
int v ;
num++ ;
do{
v=mystack[top--] ;
instack[v]= ;
belong[v]=num ;
// sum[num]++ ;
}while(v!=u) ;
}
}
void init(){
idx= ;
top=- ;
num= ;
id=;
memset(dfn,-,sizeof(dfn)) ;
memset(vec,-,sizeof(vec)) ;
memset(instack,,sizeof(instack)) ;
// memset(sum,0,sizeof(sum)) ;
}
int N ;
int judge(){
for(int i=;i<=N;i++){
if(belong[i]==belong[i+N])
return ;
}
return ;
}
struct Line{
int s ;
int t ;
};
Line L[Max_N] ;
int cross(Line A ,Line B){
if(B.s<A.s&&A.s<B.t&&B.t<A.t)
return ;
if(A.s<B.s&&B.s<A.t&&A.t<B.t)
return ;
return ;
}
int main(){
int m ;
while(scanf("%d%d",&m,&N)!=EOF){
for(int i=;i<=N;i++)
scanf("%d%d",&L[i].s,&L[i].t) ;
init() ;
for(int i=;i<=N;i++)
for(int j=i+;j<=N;j++){
if(cross(L[i],L[j])){
add_edge(i,j+N) ;
add_edge(j,i+N) ;
add_edge(i+N,j) ;
add_edge(j+N,i) ;
}
}
for(int i=;i<=*N;i++){
if(dfn[i]==-)
tarjan(i) ;
}
if(judge())
puts("panda is telling the truth...") ;
else
puts("the evil panda is lying again") ;
}
return ;
}

POJ 3207 Ikki's Story IV - Panda's Trick的更多相关文章

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

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

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

  4. POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT,基础)

    题意: 有一个环,环上n个点,现在在m个点对之间连一条线,线可以往圆外面绕,也可以往里面绕,问是否必定会相交? 思路: 根据所给的m条边可知,假设给的是a-b,那么a-b要么得绕环外,要么只能在环内, ...

  5. poj 3207 Ikki's Story IV - Panda's Trick【2-SAT+tarjan】

    注意到相交的点对一定要一里一外,这样就变成了2-SAT模型 然后我建边的时候石乐志,实际上不需要考虑这个点对的边是正着连还是反着连,因为不管怎么连,能相交的总会相交,所以直接判相交即可 然后tarja ...

  6. POJ 3207 Ikki's Story IV - Panda's Trick 2-sat模板题

    题意: 平面上,一个圆,圆的边上按顺时针放着n个点.现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接.给你的信息中,每个点最多只会连接的一条边.问能不能连接这m条边,使这 ...

  7. 【POJ】3207 Ikki's Story IV - Panda's Trick

    http://poj.org/problem?id=3207 题意:一个圆上顺时针依次排列着标号为1-n的点,这些点之间共有m条边相连,每两个点只能在圆内或者圆外连边.问是否存在这些边不相交的方案.( ...

  8. 【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 ...

  9. Ikki's Story IV - Panda's Trick POJ - 3207(水2 - sat 在圈内 还是 在圈外)

    题意: 就是一个圈上有n个点,给出m对个点,这m对个点,每一对都有一条边,合理安排这些边在圈内或圈外,能否不相交 解析: 我手残 我手残 我手残 写一下情况 只能是一个在圈外 一个在圈内 即一个1一个 ...

随机推荐

  1. javascript util.js

    //根据Id获得页面元素 function $(para) {    return document.getElementById(para);} //创建一个新的元素function createE ...

  2. HTML5跨浏览器表单及HTML5表单的渐进增强

    HTML5跨浏览器表单 http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-cross-browser-html5-f ...

  3. Python基础教程【读书笔记】 - 2016/7/5

    希望通过博客园持续的更新,分享和记录Python基础知识到高级应用的点点滴滴! 第三波:第8章  异常 [总览]学习如何创建和引发自定义的异常,以及处理异常的各种方法. 为了能够处理异常事件,可以再所 ...

  4. bzoj1173: [Balkan2007]Point

    Description 给出N个三维空间上的点. 问有多少条直线,这些直线上至少有三个点. Input 第一行给出数字N,N在[4,1000] 下面N行,每行三个数字,用于描述点的坐标,其值在[-10 ...

  5. 【原】C# decimal字符串转成整数

    第一种方法: string na="1000.53"; int a=int.Parse(na.Substring(0,na.IndexOf('.')));//返回值a=1000 第 ...

  6. J2EE学习中一些值得研究的开源项(转)

    这篇文章写在我研究J2SE.J2EE近三年后.前3年我研究了J2SE的Swing.Applet.Net.RMI.Collections. IO.JNI……研究了J2EE的JDBC.Sevlet.JSP ...

  7. Studio-----快捷键大全

    Ctrl+Alt+Space 类名或接口名提示; 补充布局的提示: 26. Ctrl+Alt+Space是类名自动完成 Ctrl+X 删除行 Ctrl+D 复制行 Alt+回车 导入包,自动修正 Cr ...

  8. Java链式方法 连贯接口(fluent interface)

    有两种情况可运用链式方法: 第一种  除最后一个方法外,每个方法都返回一个对象 object2 = object1.method1(); object3 = object2.method2(); ob ...

  9. js实现未知宽高的元素在指定元素中垂直水平居中

    js实现未知宽高的元素在指定元素中垂直水平居中:本章节介绍一下如何实现未知宽高的元素在指定元素下实现垂直水平居中效果,下面就以span元素为例子,介绍一下如何实现span元素在div中实现水平垂直居中 ...

  10. java多线程之生存者与消费者(Java编程思想)

    1.通过wait() 与 Notify实现 package Produce; import java.util.concurrent.ExecutorService; import java.util ...