题目

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裸题

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

  1. #include<iostream>
  2. #include<cmath>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<algorithm>
  6. #define LL long long int
  7. #define REP(i,n) for (int i = 1; i <= (n); i++)
  8. #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
  9. #define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts("");
  10. using namespace std;
  11. const int maxn = 1005,maxm = 1000005,INF = 1000000000;
  12. inline int read(){
  13. int out = 0,flag = 1; char c = getchar();
  14. while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
  15. while (c >= 48 && c <= 57) {out = (out << 3) + (out << 1) + c - '0'; c = getchar();}
  16. return out * flag;
  17. }
  18. int n,m,h[maxn],ne = 0;
  19. struct EDGE{int to,nxt;}ed[maxm];
  20. inline void build(int u,int v){
  21. ed[ne] = (EDGE){v,h[u]}; h[u] = ne++;
  22. }
  23. struct node{int l,r;}e[maxn];
  24. inline bool operator <(const node& a,const node& b){
  25. return a.l == b.l ? a.r < b.r : a.l < b.l;
  26. }
  27. int dfn[maxn],low[maxn],Scc[maxn],scci = 0,cnt = 0,st[maxn],top = 0;
  28. void dfs(int u){
  29. dfn[u] = low[u] = ++cnt;
  30. st[++top] = u;
  31. Redge(u)
  32. if (!dfn[to = ed[k].to])
  33. dfs(to),low[u] = min(low[u],low[to]);
  34. else if (!Scc[to]) low[u] = min(low[u],dfn[to]);
  35. if (dfn[u] == low[u]){
  36. scci++;
  37. do{Scc[st[top]] = scci;}while (st[top--] != u);
  38. }
  39. }
  40. int main(){
  41. while (~scanf("%d%d",&n,&m)){
  42. REP(i,m){
  43. e[i].l = read(),e[i].r = read();
  44. if (e[i].l > e[i].r) swap(e[i].l,e[i].r);
  45. }
  46. sort(e + 1,e + 1 + m);
  47. for (int i = 1; i <= m; i++)
  48. for (int j = i + 1; j <= m; j++)
  49. if (e[j].l <= e[i].r && e[j].r >= e[i].r){
  50. build(2 * i,2 * j - 1),build(2 * j,2 * i - 1);
  51. build(2 * i - 1,2 * j),build(2 * j - 1,2 * i);
  52. }
  53. else break;
  54. for (int i = 1; i <= (m << 1); i++) if (!dfn[i]) dfs(i);
  55. bool flag = true;
  56. for (int i = 1; i <= m; i++) if (Scc[2 * i] == Scc[2 * i - 1]){
  57. flag = false; break;
  58. }
  59. if (flag) puts("panda is telling the truth...");
  60. else puts("the evil panda is lying again");
  61. }
  62. return 0;
  63. }

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. selective search生成.mat文件

    https://github.com/sergeyk/selective_search_ijcv_with_python 里的selective_search.py是python接口 import t ...

  2. AngularJs学习笔记-数据绑定、管道

    数据绑定.管道 (1)数据绑定(Angular中默认是单向绑定) 1.[]方括号 可以用于子组件传值 由于是单向绑定,所以当子组件中的iStars属性发生改变时,不会影响到父组件中product.ra ...

  3. python内置函数map/reduce/filter

    python有几个内置的函数很有意 思:map/filter/reduce,都是对一个集合进行处理,filter很容易理解用于过滤,map用于映射,reduce用于归并. 是python列表方法的三架 ...

  4. 对于无法激活的系统—使用rearm命令延长试用期

    1.首先安装后,有一个30天的使用期. 2.在30天试用期即将结束时,用rearm命令后重启电脑,剩余时间又回复到30天.微软官方文档中声明该命令只能重复使用3次,也说是说总共可以免费体验120天. ...

  5. 前端开发APP,从HBuilder开始~

    内容简介 介绍目前前端人员开发app的几种方法,具体介绍hbuilder开发app,一扇赞新的大门~ 无所不能的js 最开始js仅仅局限于网页上一些效果,操作网页内容等, 但是nodejs把js带入了 ...

  6. display :inline-block 处理点小障碍

    使用inline-block之前先处理点小障碍:inline-block元素会有4px左右的空隙,这个是因为我们写代码时候的换行符所致. 解决办法很简单:在inline-block的父元素中设置样式f ...

  7. Solr7部署报错:java.lang.NoSuchMethodError: javax.servlet.ServletInputStream.isFinished()Z

    错误信息: Servlet.service() for servlet [default] in context with path [/solr] threw exception [Filter e ...

  8. (新手)使用pandas操作EXCEL

    import pandas as pdimport numpy as npfrom pandas import DataFrame,Series#path = r'C:\Users\tsl\Deskt ...

  9. Entrez Direct

    安装 cd ~/bin/bashperl -MNet::FTP -e \'$ftp = new Net::FTP("ftp.ncbi.nlm.nih.gov", Passive = ...

  10. [BZOJ1208]宠物收养所(Splay)

    Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望领养到自己满意的宠物,阿Q根据领养者的要求通过他自己发明的一个特 ...