题目

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.

输入格式

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 a line, either “panda is telling the truth...” or “the evil panda is lying again”.

输入样例

4 2

0 1

3 2

输出样例

panda is telling the truth...

题解

2-sat裸题

如果两条连线的区间有相交,那么就不能同时在圆的一侧

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts("");
using namespace std;
const int maxn = 1005,maxm = 1000005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = (out << 3) + (out << 1) + c - '0'; c = getchar();}
return out * flag;
}
int n,m,h[maxn],ne = 0;
struct EDGE{int to,nxt;}ed[maxm];
inline void build(int u,int v){
ed[ne] = (EDGE){v,h[u]}; h[u] = ne++;
}
struct node{int l,r;}e[maxn];
inline bool operator <(const node& a,const node& b){
return a.l == b.l ? a.r < b.r : a.l < b.l;
}
int dfn[maxn],low[maxn],Scc[maxn],scci = 0,cnt = 0,st[maxn],top = 0;
void dfs(int u){
dfn[u] = low[u] = ++cnt;
st[++top] = u;
Redge(u)
if (!dfn[to = ed[k].to])
dfs(to),low[u] = min(low[u],low[to]);
else if (!Scc[to]) low[u] = min(low[u],dfn[to]);
if (dfn[u] == low[u]){
scci++;
do{Scc[st[top]] = scci;}while (st[top--] != u);
}
}
int main(){
while (~scanf("%d%d",&n,&m)){
REP(i,m){
e[i].l = read(),e[i].r = read();
if (e[i].l > e[i].r) swap(e[i].l,e[i].r);
}
sort(e + 1,e + 1 + m);
for (int i = 1; i <= m; i++)
for (int j = i + 1; j <= m; j++)
if (e[j].l <= e[i].r && e[j].r >= e[i].r){
build(2 * i,2 * j - 1),build(2 * j,2 * i - 1);
build(2 * i - 1,2 * j),build(2 * j - 1,2 * i);
}
else break;
for (int i = 1; i <= (m << 1); i++) if (!dfn[i]) dfs(i);
bool flag = true;
for (int i = 1; i <= m; i++) if (Scc[2 * i] == Scc[2 * i - 1]){
flag = false; break;
}
if (flag) puts("panda is telling the truth...");
else puts("the evil panda is lying again");
}
return 0;
}

POJ3207 Ikki's Story IV - Panda's Trick 【2-sat】的更多相关文章

  1. poj 3207 Ikki's Story IV - Panda's Trick【2-SAT+tarjan】

    注意到相交的点对一定要一里一外,这样就变成了2-SAT模型 然后我建边的时候石乐志,实际上不需要考虑这个点对的边是正着连还是反着连,因为不管怎么连,能相交的总会相交,所以直接判相交即可 然后tarja ...

  2. POJ3207 Ikki's Story IV – Panda's Trick

    Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9426   Accepted: 3465 Description liym ...

  3. poj3207 Ikki’s Story IV – Panda’s Trick

    2-SAT. tarjan缩点.强连通分量的点要选一起选. #include<cstdio> #include<algorithm> #include<cstring&g ...

  4. POJ-3207 Ikki's Story IV - Panda's Trick 2sat

    题目链接:http://poj.org/problem?id=3207 题意:在一个圆圈上有n个点,现在用线把点两两连接起来,线只能在圈外或者圈内,现给出m个限制,第 i 个点和第 j 个点必须链接在 ...

  5. poj3207 Ikki's Story IV - Panda's Trick 2-SAT

    题目传送门 题意:在一个圆上顺时针安放着n个点,给出m条线段连接端点,要求线段不相交,线段可以在圆内也可以在圆外,问是否可以. 思路:假设一条线段,放在圆外是A,放在园内是A',那么两条线段如果必须一 ...

  6. poj3207 Ikki's Story IV - Panda's Trick 2-sat问题

    ---题面--- 题意:给定一个圈,m条边(给定),边可以通过外面连,也可以通过里面连,问连完这m条边后,是否可以做到边两两不相交 题解: 将连里面和连外面分别当做一种决策(即每条边都是决策点), 如 ...

  7. 【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 ...

  8. 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 ...

  9. 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   ...

随机推荐

  1. python剑指offer系列二叉树中和为某一值的路径

    题目描述 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中,数组长度大 ...

  2. CUDA编程时,线程块的处理方法

  3. Sql中的if函数学习

    今天,在修改项目bug时遇到一些需要计算的功能实现,虽然可以用java代码写,但是由于时间较为充裕,有尝试用sql写一下,学习到了if函数 , o.containerSendNet),) transi ...

  4. java常用 开源

    http://sourceforge.nethttp://code.google.com/hosting/http://www.open-open.com/code/tags/Javahttp://w ...

  5. IBM MQ Explore使用

    一,版本说明: 系统:win10.MQ:V9.04 二.关于帮助文档: 1.读了差不多一大半,个人感觉说明的比较生僻,应该是直译过来的.但是还是可以从这里面学一下基本的操作. 2.对于一些基本的操作, ...

  6. spring中@Autowrite注解和@Resource的区别

    spring不但支持自己定义的@Autowired注解,还支持几个由JSR-250规范定义的注解,它们分别是@Resource.@PostConstruct以及@PreDestroy. @Resour ...

  7. .NET下寄宿于控制台的HTTPS监听

    附上原文链接:https://blogs.msdn.microsoft.com/jpsanders/2009/09/29/how-to-walkthrough-using-httplistener-o ...

  8. MySQL - FULL JOIN

    SQL FULL JOIN 关键字 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行. FULL JOIN 关键字语法 SELECT column_name(s) FROM table_n ...

  9. 04.VUE学习之v-text v-html

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  10. python3爬虫之Urllib库(二)

    在上一篇文章中,我们大概讲了一下urllib库中最重要的两个请求方法:urlopen()  和  Request() 但是仅仅凭借那两个方法无法执行一些更高级的请求,如Cookies处理,代理设置等等 ...