• poj 3207 Ikki's Story IV


    Ikki's Story IV - Panda's Trick

     POJ - 3207 

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

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #define maxn 1010
    using namespace std;
    int n,m,num,head[maxn],dfn[maxn],low[maxn],cnt,st[maxn],group,top,belong[maxn];
    bool in[maxn];
    int x[maxn],y[maxn];
    struct node{int to,pre;}e[maxn*maxn];
    void Insert(int from,int to){
        e[++num].to=to;
        e[num].pre=head[from];
        head[from]=num;
    }
    bool check(){
        for(int i=1;i<=m;i++)
            if(belong[i]==belong[i+m])return 0;
        return 1;
    }
    void Tarjan(int u){
        in[u]=1;st[++top]=u;
        dfn[u]=low[u]=++cnt;
        for(int i=head[u];i;i=e[i].pre){
            int v=e[i].to;
            if(!dfn[v]){
                Tarjan(v);
                low[u]=min(low[u],low[v]);
            }
            else if(in[v])
                low[u]=min(low[u],dfn[v]);
        }
        if(dfn[u]==low[u]){
            group++;
            while(st[top]!=u){
                in[st[top]]=0;
                belong[st[top]]=group;
                top--;
            }
            top--;
            in[u]=0;belong[u]=group;
        }
    }
    int main(){
        scanf("%d%d",&n,&m);
        for(int i=1;i<=m;i++){
            scanf("%d%d",&x[i],&y[i]);
            x[i]++;y[i]++;
            if(x[i]>y[i])swap(x[i],y[i]);
        }
        for(int i=1;i<=m;i++)
            for(int j=i+1;j<=m;j++)
            if((x[i]<=x[j]&&y[i]>=x[j]&&y[i]<=y[j])||(x[i]>=x[j]&&x[i]<=y[j]&&y[i]>=y[j])){
                Insert(i,j+m);
                Insert(j,i+m);
                Insert(i+m,j);
                Insert(j+m,i);
            }
        n=2*m;
        for(int i=1;i<=n;i++)
            if(!dfn[i])Tarjan(i);
        if(check())puts("panda is telling the truth...");
        else puts("the evil panda is lying again");
        return 0;
    }
  • 相关阅读:
    echarts
    联合省选2021游记
    高维 FWT 学习笔记
    Unicode简介
    mac安装brew
    原生JS实现分页跳转
    Kubernetes Pod Probes 探针解析
    Kubernetes Secrets
    Kubernetes Container lifecycle hooks
    个人作业1——四则运算题目生成程序(基于java)
  • 原文地址:https://www.cnblogs.com/thmyl/p/8979277.html
Copyright © 2020-2023  润新知