Ikki's Story IV - Panda's Trick_poj3207_2-sat

19 篇文章 0 订阅
9 篇文章 0 订阅


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

题目大意:

有一个圆圈,要在上面连线。一条线可以画在圆的外面,也可以画在圆的里面。给出m条线段,求这些线段能否两两不相交。

思路:

把一条线拆成两种可能,连在外面和连在里面,计作点i和点i'。输入的时候判断每两条线段的关系,然后苦逼地如下枚举:

如果两条边ij必须一个画在内部,一个画在外部(判断是否有重叠的部分)

那么连边:

  i->j,

  j->

  I->j

  J->i

因为只要求我们判断是否有解,tarjan偷懒大法。

源代码/pas:

 

type
  point=record
  x,y,next:longint;
end;
var
  n,m,t,maxE:longint;
  e:array[0..2000001]of point;
  ls,low,dfn,s,comp:array[0..1000]of longint;
  v:array[0..1000]of boolean;
function min(a,b:longint):longint;
begin
  min:=a;
  if b<a then
  min:=b;
end;
procedure add(x,y:Longint);
begin
  inc(maxE);
  e[maxE].x:=x;
  e[maxE].y:=y;
  e[maxE].next:=ls[x];
  ls[x]:=maxE;
End;
procedure tarjan(x:longint);
var
  i,y:longint;
begin
  inc(t);
  dfn[x]:=t;
  low[x]:=t;
  inc(s[0]);
  s[s[0]]:=x;
  v[x]:=true;
  i:=ls[x];
  while i>0 do
  begin
    y:=e[i].y;
    if dfn[y]=0 then
    begin
      tarjan(y);
      low[x]:=min(low[y],low[x]);
    end
    else
    if v[y] then
    low[x]:=min(low[x],dfn[y]);
    i:=e[i].next;
  end;
  if dfn[x]=low[x] then
  begin
    inc(comp[0]);
    repeat
      y:=s[s[0]];
      comp[y]:=comp[0];
      v[y]:=false;
      dec(s[0]);
    until x=y;
  end;
end;
procedure check;
var
  i:longint;
begin
  for i:=1 to n*2 do
  if dfn[i]=0 then
  tarjan(i);
  for i:=1 to n do
  if comp[i]=comp[i+n] then
  begin
    writeln('the evil panda is lying again');
    halt;
  End;
  writeln('panda is telling the truth...');
End;
procedure main;
var
  i,j:longint;
  x,y:array[1..1000]of longint;
begin
  fillchar(x,sizeof(x),0);
  fillchar(y,sizeof(y),0);
  readln(m,n);
  for i:=1 to n do
  begin
    read(x[i],y[i]);
    inc(x[i]);
    inc(y[i]);
    if x[i]>y[i] then
    begin
      x[i]:=x[i] xor y[i];
      y[i]:=x[i] xor y[i];
      x[i]:=x[i] xor y[i];
    End;
  end;
  for i:=1 to n-1 do
  for j:=i+1 to n do
  if ((x[i]<=x[j])and(y[i]>=x[j])and(y[i]<=y[j]))
   or((x[i]>=x[j])and(x[i]<=y[j])and(y[i]>=y[j])) then
  begin
    add(i,j+n);
    add(j,i+n);
    add(i+n,j);
    add(j+n,i);
  end;
  check;
end;
begin
  main;
end.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值