http://poj.org/problem?id=3207

题意:一个圆上顺时针依次排列着标号为1~n的点,这些点之间共有m条边相连,每两个点只能在圆内或者圆外连边。问是否存在这些边不相交的方案。(n<=1000, m<=500)

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <iostream>
  6. using namespace std;
  7. #define zero(x) ((x)<<1)
  8. #define one(x) (zero(x)|1)
  9. const int N=1005;
  10. struct E { int next, to; }e[(N*N)<<2];
  11. int ihead[N], cnt, tot, num, FF[N], LL[N], vis[N], s[N], top, p[N], X[N], Y[N], n, m;
  12. void add(int x, int y) { e[++cnt]=(E){ihead[x], y}; ihead[x]=cnt; }
  13. void tarjan(int x) {
  14. FF[x]=LL[x]=++tot; s[++top]=x; vis[x]=1;
  15. for(int i=ihead[x]; i; i=e[i].next) {
  16. if(!FF[e[i].to]) tarjan(e[i].to), LL[x]=min(LL[x], LL[e[i].to]);
  17. else if(vis[x]) LL[x]=min(LL[x], FF[e[i].to]);
  18. }
  19. if(FF[x]==LL[x]) {
  20. int y;
  21. ++num;
  22. do {
  23. y=s[top--];
  24. vis[y]=0;
  25. p[y]=num;
  26. } while(x!=y);
  27. }
  28. }
  29. bool work() {
  30. int mm=m<<1;
  31. for(int i=0; i<mm; ++i) if(!FF[i]) tarjan(i);
  32. for(int i=0; i<mm; i+=2) if(p[i]==p[i+1]) return false;
  33. return true;
  34. }
  35. void clr() {
  36. int mm=m<<1;
  37. memset(ihead, 0, sizeof(int)*(mm));
  38. memset(FF, 0, sizeof(int)*(mm));
  39. memset(p, 0, sizeof(int)*(mm));
  40. cnt=tot=top=num=0;
  41. }
  42. int main() {
  43. while(~scanf("%d%d", &n, &m)) {
  44. for(int i=0; i<m; ++i) { scanf("%d%d", &X[i], &Y[i]); if(X[i]>Y[i]) swap(X[i], Y[i]); }
  45. for(int i=0; i<m; ++i) {
  46. int a=X[i], b=Y[i];
  47. for(int j=0; j<m; ++j) if(i!=j) {
  48. int c=X[j], d=Y[j];
  49. if((a<c && c<b && (a>d || d>b)) || (a<d && d<b && (a>c || c>b)))
  50. add(zero(i), one(j)), add(one(i), zero(j));
  51. }
  52. }
  53. if(!work()) puts("the evil panda is lying again");
  54. else puts("panda is telling the truth...");
  55. clr();
  56. }
  57. return 0;
  58. }

  

容易发现一条边连圆内那么在圆内的其它边与这条边有交的那么我们就连x->y'。如果一条边连在圆外那么圆外的其他边有交的我们就连x'->y。

那么搞搞就行辣= =

(现在写tarjan缩点辣~具体算法看论文 伍昱:《由对称性解2-SAT问题》

【POJ】3207 Ikki's Story IV - Panda's Trick的更多相关文章

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

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

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

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

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

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

  6. POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT,基础)

    题意: 有一个环,环上n个点,现在在m个点对之间连一条线,线可以往圆外面绕,也可以往里面绕,问是否必定会相交? 思路: 根据所给的m条边可知,假设给的是a-b,那么a-b要么得绕环外,要么只能在环内, ...

  7. POJ 3207 Ikki's Story IV - Panda's Trick 2-sat模板题

    题意: 平面上,一个圆,圆的边上按顺时针放着n个点.现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接.给你的信息中,每个点最多只会连接的一条边.问能不能连接这m条边,使这 ...

  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. POJ3207 Ikki's Story IV - Panda's Trick 【2-sat】

    题目 liympanda, one of Ikki's friend, likes playing games with Ikki. Today after minesweeping with Ikk ...

随机推荐

  1. gcc【数学几何】

    GCC Time Limit: 1000MS Memory limit: 65536K 题目描述 The GNU Compiler Collection (usually shortened to G ...

  2. SQLAlchemy ORM高级查询之过滤,排序

    order_by,filter的语法. 用久了才会熟悉. Session = sessionmaker(bind=engine) session = Session() print(session.q ...

  3. POJ3294 Life Forms(后缀数组)

    引用罗穗骞论文中的话: 将n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组.然后二分答案,用和例3 同样的方法将后缀分成若干组,判断每组的后缀是否出现在不小于k 个的原串中 ...

  4. php array_intersect() 和 array_diff() 函数

    在PHP中,使用 array_intersect 求两个数组的交集比使用 array_diff 求同样两个数组的并集要快. 如果要求数组 $a 与数组 $b 的差集的个数,应该使用 count($a) ...

  5. C# 创建Windows Service

    当我们需要一个程序长期运行,但是不需要界面显示时可以考虑使用Windows Service来实现.这篇博客将简单介绍一下如何创建一个Windows Service,安装/卸载Windows Servi ...

  6. 【leetcode】Remove Duplicates from Sorted Array

    题目描述: Given a sorted array, remove the duplicates in place such that each element appear only once a ...

  7. Zero Copy 简介

    转自:http://blog.csdn.net/zzz_781111/article/details/7534649 许多web应用都会向用户提供大量的静态内容,这意味着有很多data从硬盘读出之后, ...

  8. MySQL模糊查询:LIKE模式和REGEXP模式

    MySQL模糊查询提供了两种模式:LIKE模式和REGEXP模式. LIKE模式 LIKE模式是使用的LIKE 或 NOT LIKE 比较运算符进行模糊查询. SELECT 字段 FROM 表 WHE ...

  9. 【SSH】 之 Struts2

    (一)Struts2是什么? Struts2是一个基于MVC设计模式的Web应用框架,它本质上相当于一个servlet,在MVC设计模式中,Struts2作为控制器(Controller)来建立模型与 ...

  10. MFC中afx_msg是什么,afx_msg void function()是什么意思

    应用程序框架产生的消息映射函数例如:afx_msg void OnBnClickedButton1(); 其中 afx_msg为消息标志,它向系统声明:有消息映射到函数实现体:而在map宏定义中,就有 ...