Language:
Default
Ikki's Story IV - Panda's Trick
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 8796   Accepted: 3241

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

题意:有n个点在一个圆上。标号0~n-1。有m条线段告诉两个端点的标号。每条线段能够在画在圆内也能够画在圆外。问这m条线段是否能不向交。

思路:2-SAT模板题,把每条线段当做节点。每条线有两种状态(圆内和圆外。两者仅仅能取其一),建图后求强连通,看 i 和 i‘ 是否在同一个连通分量,若在则无解,否则有解。

參考:由对称性解2-SAT问题  还有 kuangbin神牛的总结点击打开链接

代码:

#include <iostream>
#include <functional>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define pi acos(-1.0)
#define eps 1e-6
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define DBG pf("Hi\n")
typedef long long ll;
using namespace std; #define INF 0x3f3f3f3f
#define mod 1000000009
const int maxn = 1005;
const int MAXN = 2005;
const int MAXM = 200010;
const int N = 1005; struct Edge
{
int to,next;
}edge[MAXM]; int head[MAXN],tot; void init()
{
tot=0;
memset(head,-1,sizeof(head));
} void addedge(int u,int v)
{
edge[tot].to=v;
edge[tot].next=head[u];
head[u]=tot++;
} int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];
int Index,scc,top;
bool Instack[MAXN]; void Tarjan(int u)
{
int v;
Low[u]=DFN[u]=++Index;
Stack[top++]=u;
Instack[u]=true;
for (int i=head[u];~i;i=edge[i].next)
{
v=edge[i].to;
if (!DFN[v])
{
Tarjan(v);
if (Low[u]>Low[v])
Low[u]=Low[v];
}
else if (Instack[v]&&Low[u]>DFN[v])
Low[u]=DFN[v];
}
if (Low[u]==DFN[u])
{
++scc;
do{
v=Stack[--top];
Instack[v]=false;
Belong[v]=scc;
}while (v!=u);
}
return ;
} bool solvable(int n)
{
memset(DFN,0,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
Index=scc=top=0;
for (int i=0;i<n;i+=2)
if (!DFN[i])
Tarjan(i);
for (int i=0;i<n;i+=2)
{
if (Belong[i]==Belong[i^1])
return false;
}
return true;
} struct Line
{
int s,t;
}line[MAXN]; int n,m; int main()
{
#ifndef ONLINE_JUDGE
freopen("C:/Users/lyf/Desktop/IN.txt","r",stdin);
#endif
int i,j;
scanf("%d%d",&n,&m);
init();
for (i=0;i<m;i++)
{
scanf("%d%d",&line[i].s,&line[i].t);
if (line[i].s>line[i].t) swap(line[i].s,line[i].t);
}
for (i=0;i<m;i++)
{
for (j=i+1;j<m;j++)
{
if (line[i].s<line[j].s&&line[i].t>line[j].s&&line[i].t<line[j].t||line[j].s<line[i].s&&line[j].t>line[i].s&&line[j].t<line[i].t)
{
addedge(2*i,2*j+1);
addedge(2*j+1,2*i);
addedge(2*j,2*i+1);
addedge(2*i+1,2*j);
}
}
}
if (solvable(m*2))
printf("panda is telling the truth...\n");
else
printf("the evil panda is lying again\n");
return 0;
}

Ikki&#39;s Story IV - Panda&#39;s Trick (poj 3207 2-SAT)的更多相关文章

  1. [2-SAT] poj 3207 Ikki&#39;s Story IV - Panda&#39;s Trick

    题目链接: id=3207">http://poj.org/problem? id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1 ...

  2. POJ 3207 Ikki&#39;s Story IV - Panda&#39;s Trick(2-sat)

    POJ 3207 Ikki's Story IV - Panda's Trick id=3207" target="_blank" style=""& ...

  3. POJ 3207 Ikki&#39;s Story IV - Panda&#39;s Trick (2-SAT)

    职务地址:id=3207">POJ 3207 找好矛盾关系.矛盾关系是(2,5)和(3,6)这两个仅仅能一个在外边,一个在里边.利用这个矛盾关系来建图. 能够用在外边和里边来当1和0, ...

  4. Ikki's Story IV - Panda's Trick POJ - 3207(水2 - sat 在圈内 还是 在圈外)

    题意: 就是一个圈上有n个点,给出m对个点,这m对个点,每一对都有一条边,合理安排这些边在圈内或圈外,能否不相交 解析: 我手残 我手残 我手残 写一下情况 只能是一个在圈外 一个在圈内 即一个1一个 ...

  5. POJ 3207 Ikki's Story IV - Panda's Trick

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7296   ...

  6. poj 3207 Ikki's Story IV - Panda's Trick (2-SAT)

    http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 13 ...

  7. POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题)

    POJ 3207 Ikki's Story IV - Panda's Trick(2-sat问题) Description liympanda, one of Ikki's friend, likes ...

  8. 【POJ3207】Ikki's Story IV - Panda's Trick

    POJ 3207 Ikki's Story IV - Panda's Trick liympanda, one of Ikki's friend, likes playing games with I ...

  9. POJ 3207 Ikki's Story IV - Panda's Trick (2-sat)

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6691   ...

随机推荐

  1. CentOS 下通过命令登录Mysql

    CentOS 下通过命令登录Mysql: mysql -uroot -p 按回车键后输入密码

  2. 命令行-s的意思

    -s,signal,意思就是信号,一般是发送信号. 如: # 关闭 nginx -s stop;

  3. EasyUI 动态生成列加分页

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...

  4. [BZOJ3339] Rmq Problem(线段树)

    传送门 这个题的方法好像很多啊 1.莫队暴力 2.线段树 + 离线处理 先预处理出sg[i]表示前i个数的sg值,next[i]表示i的下一位置在哪里,如果后面再没有i,那么next[i] = n + ...

  5. NOI2015 荷马史诗 【k-哈夫曼树】

    题目 追逐影子的人,自己就是影子 --荷马 Allison 最近迷上了文学.她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的<荷马史诗>.但是由<奥德赛> ...

  6. 【jquery创建元素添加元素】

    使用jquery创建新元素的方法为:$(html标签),例如 $("<p></p>")创建了一个段落.注意此时只是创建了对象,尚未添加到文档节点中去:以下四 ...

  7. Linux(13):期中架构(5)--- 前端部分:keepalived高可用 & HTTPS & iptables防火墙

    keepalived 高可用集群 1. keepalived服务概念说明 # 1.1 keepalived软件的作用? Keepalived软件起初是专为LVS负载均衡软件设计的, 用来管理并监控LV ...

  8. 酒厂选址(codevs 1507)

    题目描述 Description Abstinence(戒酒)岛的居民们酷爱一种无酒精啤酒.以前这种啤酒都是从波兰进口,但今年居民们想建一个自己的啤酒厂.岛上所有的城市都坐落在海边,并且由一条沿海岸线 ...

  9. CF 527C Glass Carving

    数据结构维护二维平面 首先横着切与竖着切是完全没有关联的, 简单贪心,最大子矩阵的面积一定是最大长*最大宽 此处有三种做法 1.用set来维护,每次插入操作寻找这个点的前驱和后继,并维护一个计数数组, ...

  10. 【HDOJ6228】Tree(树)

    题意:有一棵n个点的树,在树上的点涂色,每个点涂一种颜色,一共可以涂k种颜色, 然后把同一种颜色(比如说x)的点用最优方案连起来,在连线的边涂上x颜色,问涂k次的边最多有几条 k<=500 si ...