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 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/5674031.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值