poj3207 Ikki's Story IV - Panda's Trick

http://www.elijahqi.win/archives/3066
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

POJ Monthly–2007.03.04, Ikki
判断条件
a[i]< a[j]&&b[i]< b[j]&&b[i]>a[j]||a[j]< a[i]&&b[j]< b[i]&&b[j]>a[i]
满足这种情况两条线就必须一个在里面一个在外面
设2*i为里面2*i+1为外面 然后就互相连边即可 注意边数是m*m*2
然后tarjan缩点判断是否有里面和外面同时出现在环上

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if(T==S) return EOF;}
    return *S++;
}
inline bool read(int &x){
    x=0;int f=1;char ch=gc();if (ch==EOF) return 0;
    while(!isdigit(ch)) {if (ch=='-') f=-1;ch=gc();}
    while(isdigit(ch)) x=x*10+ch-'0',ch=gc();x*=f;
    return 1;
}
const int N=1010;
struct node{
    int y,next;
}data[500050];
int num,h[N],dfn[N],stackf[N],q[N],top,low[N],s,b[N],n,m,a[N],bl[N]; 
inline void insert1(int x,int y){
    data[++num].y=y;data[num].next=h[x];h[x]=num;
    data[++num].y=x;data[num].next=h[y];h[y]=num;
}
inline void tarjan(int x){
    dfn[x]=low[x]=++num;stackf[x]=1;q[++top]=x;
    for (int i=h[x];i;i=data[i].next){
        int y=data[i].y;
        if (!dfn[y]) tarjan(y),low[x]=min(low[x],low[y]);else if (stackf[y]) low[x]=min(low[x],dfn[y]);
    }
    if (low[x]==dfn[x]){
        int y;++s;
        do{
            y=q[top--];stackf[y]=0;bl[y]=s;
        }while(y!=x);
    }
}
int main(){
    freopen("poj3207.in","r",stdin);
    while(read(n)&&read(m)){
        for(int i=0;i<m;++i){
            read(a[i]),read(b[i]);
            if(a[i]>b[i]) swap(a[i],b[i]);
        }
        for (int i=0;i<m;++i){
            for (int j=i+1;j<m;++j){
                if (a[i]<a[j]&&b[i]<b[j]&&b[i]>a[j]||a[j]<a[i]&&b[j]<b[i]&&b[j]>a[i])
                insert1(2*i,j*2+1),insert1(2*j,2*i+1);
            }
        }num=0;top=0;
        for (int i=0;i<2*m;++i) if (!dfn[i]) tarjan(i);bool flag=0;
        for (int i=0;i<m;++i){
            if (bl[2*i]==bl[2*i+1]){
                puts("the evil panda is lying again");
                return 0;
            }
        }puts("panda is telling the truth...");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值