职务地址:

id=3207">POJ 3207

找好矛盾关系。矛盾关系是(2,5)和(3,6)这两个仅仅能一个在外边,一个在里边。利用这个矛盾关系来建图。

能够用在外边和里边来当1和0,最后推断每对是否出现矛盾。

代码例如以下:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstring>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <ctype.h>
  8. #include <queue>
  9. #include <map>
  10. #include <set>
  11. #include <algorithm>
  12.  
  13. using namespace std;
  14. #define LL __int64
  15. const int INF=0x3f3f3f3f;
  16. int head[1100], cnt, top, ans, index;
  17. int dfn[1100], low[1100], instack[1100], stak[1100], belong[1100];
  18. struct node
  19. {
  20. int u, v, next;
  21. }edge[1000000];
  22. struct N
  23. {
  24. int l, r;
  25. }xian[10000];
  26. void add(int u, int v)
  27. {
  28. edge[cnt].v=v;
  29. edge[cnt].next=head[u];
  30. head[u]=cnt++;
  31. }
  32. int pan(N x, N y)
  33. {
  34. if((x.l>y.l&&x.l<y.r&&x.r>y.r)||(x.r>y.l&&x.r<y.r&&x.l<y.l))
  35. return 1;
  36. return 0;
  37. }
  38. void tarjan(int u)
  39. {
  40. dfn[u]=low[u]=++index;
  41. instack[u]=1;
  42. stak[++top]=u;
  43. for(int i=head[u];i!=-1;i=edge[i].next)
  44. {
  45. int v=edge[i].v;
  46. if(!dfn[v])
  47. {
  48. tarjan(v);
  49. low[u]=min(low[u],low[v]);
  50. }
  51. else if(instack[v])
  52. {
  53. low[u]=min(dfn[v],low[u]);
  54. }
  55. }
  56. if(dfn[u]==low[u])
  57. {
  58. ans++;
  59. while(1)
  60. {
  61. int v=stak[top--];
  62. instack[v]=0;
  63. belong[v]=ans;
  64. if(u==v) break;
  65. }
  66. }
  67. }
  68. void init()
  69. {
  70. memset(head,-1,sizeof(head));
  71. cnt=top=ans=index=0;
  72. memset(dfn,0,sizeof(dfn));
  73. memset(instack,0,sizeof(instack));
  74. }
  75. int main()
  76. {
  77. int n, m, i, j;
  78. scanf("%d%d",&n,&m);
  79. init();
  80. for(i=0;i<m;i++)
  81. {
  82. scanf("%d%d",&xian[i].l,&xian[i].r);
  83. if(xian[i].l>xian[i].r) swap(xian[i].l,xian[i].r);
  84. }
  85. for(i=0;i<m;i++)
  86. {
  87. for(j=0;j<i;j++)
  88. {
  89. if(pan(xian[i],xian[j]))
  90. {
  91. add(i<<1,j<<1|1);
  92. add(j<<1,i<<1|1);
  93. add(i<<1|1,j<<1);
  94. add(j<<1|1,i<<1);
  95. //printf("%d %d\n%d %d\n",i<<1,j<<1|1,j<<1,i<<1|1);
  96. }
  97. }
  98. }
  99. for(i=0;i<2*m;i++)
  100. {
  101. if(!dfn[i])
  102. tarjan(i);
  103. }
  104. int flag=0;
  105. for(i=0;i<m;i++)
  106. {
  107. if(belong[i<<1]==belong[i<<1|1])
  108. {
  109. flag=1;
  110. //printf("%d\n",i);
  111. break;
  112. }
  113. }
  114. if(flag) puts("the evil panda is lying again");
  115. else
  116. puts("panda is telling the truth...");
  117. return 0;
  118. }

版权声明:本文博主原创文章,博客,未经同意,不得转载。

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

  1. 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=""& ...

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

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

    Language: Default Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total S ...

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

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

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

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

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

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

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

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

随机推荐

  1. Oracle中decode函数 列变成行

    create table t_class(c_Id  number(10) primary key ,stuName varchar2(50),  --人名c_Name varchar2(50),   ...

  2. 《JavaScript设计模式与开发实践》读书笔记之策略模式

    1.策略模式 定义一系列算法,把它们一个个封装起来,并且使它们可以相互替换 1.1 传统实现 根据工资基数和年底绩效来发送年终奖 var calculateBonus= function (perfo ...

  3. Android编程之LayoutInflater的inflate方法实例

    假设你不关心其内部实现,仅仅看怎样使用的话,直接看这篇就可以. 接上篇,接下来,就用最最简单的样例来说明一下: 用两个布局文件main 和 test: 当中,main.xml文件为: <?xml ...

  4. 同时显示多个 Notification

    主要出在PendingIntent.getActivity();的第二个参数,API文档里虽然说是未被使用的参数(给出的例子也直接写0的),实际上是通过该参数来区别不同的Intent的,如果id相同, ...

  5. Android (1) - Activity

    onCreate(Bundle status) --> setContentView(View view) --> findViewById(int id) Intent intentFo ...

  6. C语言 cgi(2)

    1Columbia Universitycs3157 – Advanced ProgrammingSummer 2014, Lab #3, 40 pointsJune 10, 2014This lab ...

  7. 局域网连接SQL Server数据库配置

    首先要保证两台机器位于同一局域网内,然后打开配置工具→SQL Server配置管理器进行配置.将MSSQLSERVER的协议的TCP/IP的(IP1.IP2)TCPport改为1433,已启用改为是. ...

  8. 十步完全理解SQL(转)

    本文由 伯乐在线 - 水果泡腾片 翻译.未经许可,禁止转载!英文出处:Lukas Eder.欢迎加入翻译组. 很多程序员视 SQL 为洪水猛兽.SQL 是一种为数不多的声明性语言,它的运行方式完全不同 ...

  9. decorate pattern 装饰模式

    [装饰模式的优缺点]装饰模式的优点:1.比静态继承更灵活:2.避免在层次结构高层的类有太多的特征装饰模式的缺点:1.使用装饰模式会产生比使用继承关系更多的对象.并且这些对象看上去都很想像,从而使得查错 ...

  10. go语言实现遍历目录,及查找特定的文件类型

    // filelist.go package main import ( //"flag" "fmt" "os" "path/fi ...