Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 9426   Accepted: 3465

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

 
又是WA在数组不够大←
 
连接两个点的一段线,要么全部在圆里,要么全部在圆外
先在各段线之间连边:若是两段线可能有交叉,那么必须一个在圆里,一个在圆外
建好图后用tarjan求强连通分量,若是表示一段线在圆里和圆外的两个点在同一个强连通分量里,那么就不可行
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int mxn=;
//bas
int n,m;
int hd[mxn],cnt=;
int a[mxn],b[mxn]; //edge
struct edge{
int to;
int next;
}e[mxn];
void add_edge(int u,int v){
e[++cnt].next=hd[u];e[cnt].to=v;hd[u]=cnt;
} //tarjan
int vis[mxn];
int dfn[mxn],low[mxn];
int st[mxn],top;
bool inst[mxn];
int dtime=;
int belone[mxn],tot;
void tarjan(int s){
low[s]=dfn[s]=++dtime;
st[++top]=s;
inst[s]=;
for(int i=hd[s];i;i=e[i].next){
int v=e[i].to;
if(!dfn[v]){
tarjan(v);
low[s]=min(low[s],low[v]);
}
else if(inst[v]){
low[s]=min(low[s],dfn[v]);
}
}
int v;
if(low[s]==dfn[s]){
cnt++;
do{
v=st[top--];
inst[v]=;
belone[v]=cnt; }while(v!=s);
}
return;
} //
void Build(){
int i,j;
for(i=;i<m;i++)
for(j=i+;j<=m;j++){
if((a[i]<a[j] && a[j]<b[i] && b[i]<b[j]) ||
(a[i]>a[j] && a[i]<b[j] && b[i]>b[j]) ){
add_edge(i,j+m);//用+m的点表示在外面
add_edge(j,i+m);
add_edge(i+m,j);
add_edge(j+m,i); }
}
return;
}
int main(){
scanf("%d%d",&n,&m);
int i,j;
for(i=;i<=m;i++){
scanf("%d%d",&a[i],&b[i]);
a[i]++;b[i]++;
if(a[i]>b[i])swap(a[i],b[i]);
}
Build();
n=*m;
for(i=;i<=n;i++)if(!dfn[i])tarjan(i);
for(i=;i<=m;i++){
if(belone[i]==belone[i+m]){
printf("the evil panda is lying again");
return ;
}
}
printf("panda is telling the truth...");
return ;
}

POJ3207 Ikki's Story IV – Panda's Trick的更多相关文章

  1. POJ3207 Ikki's Story IV - Panda's Trick 【2-sat】

    题目 liympanda, one of Ikki's friend, likes playing games with Ikki. Today after minesweeping with Ikk ...

  2. poj3207 Ikki’s Story IV – Panda’s Trick

    2-SAT. tarjan缩点.强连通分量的点要选一起选. #include<cstdio> #include<algorithm> #include<cstring&g ...

  3. POJ-3207 Ikki's Story IV - Panda's Trick 2sat

    题目链接:http://poj.org/problem?id=3207 题意:在一个圆圈上有n个点,现在用线把点两两连接起来,线只能在圈外或者圈内,现给出m个限制,第 i 个点和第 j 个点必须链接在 ...

  4. poj3207 Ikki's Story IV - Panda's Trick 2-SAT

    题目传送门 题意:在一个圆上顺时针安放着n个点,给出m条线段连接端点,要求线段不相交,线段可以在圆内也可以在圆外,问是否可以. 思路:假设一条线段,放在圆外是A,放在园内是A',那么两条线段如果必须一 ...

  5. poj3207 Ikki's Story IV - Panda's Trick 2-sat问题

    ---题面--- 题意:给定一个圈,m条边(给定),边可以通过外面连,也可以通过里面连,问连完这m条边后,是否可以做到边两两不相交 题解: 将连里面和连外面分别当做一种决策(即每条边都是决策点), 如 ...

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

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

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

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

随机推荐

  1. spark&dataframe

    1.今天,我们来介绍spark以及dataframe的相关的知识点,但是在此之前先说一下对以前的hadoop的一些理解 当我启动hadoop的时候,上面有hdfs的存储结构,由于这个是分布式存储,所以 ...

  2. 大数据江湖之即席查询与分析(下篇)--手把手教你搭建即席查询与分析Demo

    上篇小弟分享了几个“即席查询与分析”的典型案例,引起了不少共鸣,好多小伙伴迫不及待地追问我们:说好的“手把手教你搭建即席查询与分析Demo”啥时候能出?说到就得做到,差啥不能差人品,本篇只分享技术干货 ...

  3. Java实现系统目录实时监听更新。

    SDK1.7新增的nio WatchService能完美解决这个问题.美中不足是如果部署在window系统下会出现莫名其妙的文件夹占用异常导致子目录监听失效,linux下则完美运行.这个问题着实让人头 ...

  4. Android 懒加载简单介绍

    1.懒加载介绍 1.1.效果预览 1.2.效果讲解 当页面可见的时候,才加载当前页面. 没有打开的页面,就不会预加载. 说白了,懒加载就是可见的时候才去请求数据. 1.3.懒加载文章传送门 参考文章: ...

  5. Android开发——弹性滑动的两种实现方式

    0. 前言   欢迎转载,转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52538723 我们在Android开发--View滑动的三 ...

  6. APP遇到大量的真实手机号刷注册用户该如何应对?

    欢迎访问网易云社区,了解更多网易技术产品运营经验. 在说如何应对之前,先给各位梳理移动端APP可能遇到哪些作弊风险.1. 渠道商刷量,伪造大量的下载量和装机量,但没有新用户注册:2. 对于电商.P2P ...

  7. 《Cracking the Coding Interview》——第9章:递归和动态规划——题目7

    2014-03-20 03:35 题目:实现画图的Flood Fill操作. 解法:DFS和BFS皆可,但BFS使用的队列在时间复杂度上常数项比较大,速度略慢,所以我选了DFS.当然,如果图很大的话D ...

  8. CSS系列(7)CSS类选择器Class详解

    这一篇文章,以笔记形式写. 1,  CSS 类选择器详解 http://www.w3school.com.cn/css/css_selector_class.asp 知识点: (1)    使用类选择 ...

  9. 【Power of Two】cpp

    题目: Given an integer, write a function to determine if it is a power of two. 代码: class Solution { pu ...

  10. Python网络编程(weekly summary1)

    网络的目的是什么?     用于信息传输.接受  能把各个点.面.体的信息链接到一起 实现资源的共享 OSI模型:     应用层:提供程序服务     表示层:数据加密.优化.压缩     会话层: ...