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 }
  • 相关阅读:
    React `${}` 格式
    echarts-for-react
    React 列表 瀑布流 修改样式瀑布流不起效果
    前端技术栈
    React 技术栈
    自定义点击body 退出登录url隐藏
    import 'element-ui/lib/theme-default/index.css'报错
    cnpm install element-ui --save
    Vue http://eslint.org/docs/rules/no-trailing-spaces 报错问题
    【loj 6363】地底蔷薇【拉格朗日反演】【生成函数】
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5674031.html
Copyright © 2011-2022 走看看