题目链接

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

分析:将每一条边缩成一个点,对于每条边要么在圆内要么在园外只有满足一种情况,将在圆内设为i,在圆外设为i',那么对于两条线(i, j)不能同时在圆内,那么也不能同时在圆外。则有四种情况 (i, j') (i', j) (j, i') (j', i)要建这四条边,然后就照着刘汝佳书上的抄了

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
const int Max = ;
struct TWOSAT
{
int n;
vector<int> G[Max * ];
bool mark[Max * ];
int S[Max * ], c;
void init(int n)
{
this->n = n;
for (int i = ; i <= n * ; i++)
G[i].clear();
memset(mark, , sizeof(mark));
}
void add_clause(int x, int y)
{
G[ * x].push_back( * y + ); //四条边
G[ * x + ].push_back( * y);
G[ * y + ].push_back( * x);
G[ * y].push_back( * x + );
}
bool dfs(int x)
{
if (mark[x ^ ])
return false;
if (mark[x])
return true;
mark[x] = true;
S[c++] = x;
for (int i = ; i < (int) G[x].size(); i++)
if (!dfs(G[x][i]))
return false;
return true;
}
bool solve()
{
for (int i = ; i <= n * ; i += )
{
if (!mark[i] && !mark[i + ])
{
c = ;
if (!dfs(i))
{
while (c > )
mark[ S[--c] ] = false;
if (!dfs(i + ))
return false;
}
}
}
return true;
}
};
struct Node
{
int s, t;
}node[Max];
int main()
{
int n, m;
while (scanf("%d%d", &n, &m) != EOF)
{
for (int i = ; i <= m; i++)
{
scanf("%d%d", &node[i].s, &node[i].t);
if (node[i].s > node[i].t) //这一步让判断相交很方便
swap(node[i].s, node[i].t);
}
TWOSAT twosat;
twosat.init(m);
for (int i = ; i <= m; i++)
{
for (int j = i + ; j <= m; j++)
{
if ( (node[i].s < node[j].s && node[i].t < node[j].t && node[i].t > node[j].s) || (node[j].s < node[i].s && node[i].t > node[j].t && node[j].t > node[i].s) ) //相交的情况, i 的起点 在 j 的 起点和终点之间并且i的终点要大于j的终点, 另一种情况类似
{
twosat.add_clause(i, j);
}
}
}
if (twosat.solve())
printf("panda is telling the truth...\n");
else
printf("the evil panda is lying again\n");
}
}

POJ3207Ikki's Story IV - Panda's Trick(模板题)的更多相关文章

  1. poj--3207--Ikki's Story IV - Panda's Trick(2-sat)

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %I64d ...

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

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

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

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

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

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

  9. 【POJ】3207 Ikki's Story IV - Panda's Trick

    http://poj.org/problem?id=3207 题意:一个圆上顺时针依次排列着标号为1-n的点,这些点之间共有m条边相连,每两个点只能在圆内或者圆外连边.问是否存在这些边不相交的方案.( ...

随机推荐

  1. 1103简单SQL 行转列思路

    转自http://www.cnblogs.com/lhj588/p/3315876.html -- 经典行列转化DROP TABLE IF EXISTS TabName;CREATE TABLE Ta ...

  2. extjs基础 使用图标字体来美化按钮)

    下载 Font Awesome 1.拷贝css 和 fonts 到build同级目录 2.需要在index.html中引入css文件 3.在main.js文件中添加 initComponent : f ...

  3. WPS显示无法创建对象,请确认对象已在系统注册表中注册

    第一种方法:在系统的开始--所有程序找到WPS--WPS office工具--配置工具--高级--兼容设置,在这里勾选兼容第三方系统和软件. 第二种方法: xp/win7系统:拷贝packager.e ...

  4. 【日常笔记】mybatis 处理 in 语句的使用

    在Mybatis的xml配置中使用集合,主要是用到了foreach动态语句. foreach的参数:foreach元素的属性主要有 item,index,collection,open,separat ...

  5. Gitlab的搭建

    从网上看了一大堆的资料,最终选定按照github上的文档来搭建,虽然本人英文不好,就这样看着 这个博客弯曲完全是拷贝过来的,只为了做个笔记 原文地址:https://github.com/gitlab ...

  6. iOS开发,应用间的跳转

    预习:URL由两部分组成-- 1.scheme:协议头(http://  ftp:// 等等) 2.path:路径(URL中path可以没有) 一.简单实现跳转到指定APP(也就是说跳转到的APP必须 ...

  7. 【BZOJ 2118】墨墨的等式

    http://www.lydsy.com/JudgeOnline/problem.php?id=2118 最短路就是为了找到最小的$x$满足$x=k×a_{min}+d,0≤d<a_{min}$ ...

  8. angular指令大全

    这篇文章的案例都是来自官方,引用的cdn来自bootcss, 因为angular的官方网站被屏了, 所以要翻, 不过我把整个文档下回来了,方便大家下载可以点击: 打开下载英文版 angular的指令 ...

  9. mysql解决无法远程客户端连接

    1. 改表法.可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 " ...

  10. Jquery-选择框点击勾选或者取消

    1:单选框,直接定位到属性名称 $(document).ready(function(){ var old = null; //用来保存原来的对象 $("input[name='sex']& ...