zoukankan      html  css  js  c++  java
  • POJ3207 Ikki's Story IV – Panda's Trick

    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求强连通分量,若是表示一段线在圆里和圆外的两个点在同一个强连通分量里,那么就不可行
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 const int mxn=600000;
     8 //bas
     9 int n,m;
    10 int hd[mxn],cnt=0;
    11 int a[mxn],b[mxn];
    12 
    13 //edge
    14 struct edge{
    15     int to;
    16     int next;
    17 }e[mxn];
    18 void add_edge(int u,int v){
    19     e[++cnt].next=hd[u];e[cnt].to=v;hd[u]=cnt;
    20 }
    21 
    22 //tarjan
    23 int vis[mxn];
    24 int dfn[mxn],low[mxn];
    25 int st[mxn],top;
    26 bool inst[mxn];
    27 int dtime=0;
    28 int belone[mxn],tot;
    29 void tarjan(int s){
    30     low[s]=dfn[s]=++dtime;
    31     st[++top]=s;
    32     inst[s]=1;
    33     for(int i=hd[s];i;i=e[i].next){
    34         int v=e[i].to;
    35         if(!dfn[v]){
    36             tarjan(v);
    37             low[s]=min(low[s],low[v]);
    38         }
    39         else if(inst[v]){
    40             low[s]=min(low[s],dfn[v]);
    41         }
    42     }
    43     int v;
    44     if(low[s]==dfn[s]){
    45         cnt++;
    46         do{    
    47             v=st[top--];
    48             inst[v]=0;
    49             belone[v]=cnt;
    50             
    51         }while(v!=s);
    52     }
    53     return;
    54 }
    55 
    56 //
    57 void Build(){
    58     int i,j;
    59     for(i=1;i<m;i++)
    60       for(j=i+1;j<=m;j++){
    61           if((a[i]<a[j] && a[j]<b[i] && b[i]<b[j]) ||
    62            (a[i]>a[j] && a[i]<b[j] && b[i]>b[j])    ){
    63                    add_edge(i,j+m);//用+m的点表示在外面 
    64                    add_edge(j,i+m);
    65                    add_edge(i+m,j);
    66                    add_edge(j+m,i);
    67                
    68            }
    69       }
    70     return;
    71 }
    72 int main(){
    73     scanf("%d%d",&n,&m);
    74     int i,j;
    75     for(i=1;i<=m;i++){
    76         scanf("%d%d",&a[i],&b[i]);
    77         a[i]++;b[i]++;
    78         if(a[i]>b[i])swap(a[i],b[i]);
    79     }
    80     Build();
    81     n=2*m;
    82     for(i=1;i<=n;i++)if(!dfn[i])tarjan(i);
    83     for(i=1;i<=m;i++){
    84         if(belone[i]==belone[i+m]){
    85             printf("the evil panda is lying again");
    86             return 0;
    87         }
    88     }
    89     printf("panda is telling the truth...");
    90     return 0;
    91 }
  • 相关阅读:
    移动web前端高效开发实践 读书笔记
    前端开发最佳实践-读书笔记
    frontend-Tips
    匿名函数的几种写法
    12个用得着的JQuery代码片段(转)
    tesseract-ocr 学习笔记(比网上的中文说明都详细)
    关于大数据的思考
    单片机实验的小记录~~PWM
    组建Redis集群遇到`GLIBC_2.14' not found和ps -ef 不显示用户名
    柔性数组(Redis源码学习)
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5674031.html
Copyright © 2011-2022 走看看