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 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】的更多相关文章
- poj 3207 Ikki's Story IV - Panda's Trick【2-SAT+tarjan】
注意到相交的点对一定要一里一外,这样就变成了2-SAT模型 然后我建边的时候石乐志,实际上不需要考虑这个点对的边是正着连还是反着连,因为不管怎么连,能相交的总会相交,所以直接判相交即可 然后tarja ...
- POJ3207 Ikki's Story IV – Panda's Trick
Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9426 Accepted: 3465 Description liym ...
- poj3207 Ikki’s Story IV – Panda’s Trick
2-SAT. tarjan缩点.强连通分量的点要选一起选. #include<cstdio> #include<algorithm> #include<cstring&g ...
- POJ-3207 Ikki's Story IV - Panda's Trick 2sat
题目链接:http://poj.org/problem?id=3207 题意:在一个圆圈上有n个点,现在用线把点两两连接起来,线只能在圈外或者圈内,现给出m个限制,第 i 个点和第 j 个点必须链接在 ...
- poj3207 Ikki's Story IV - Panda's Trick 2-SAT
题目传送门 题意:在一个圆上顺时针安放着n个点,给出m条线段连接端点,要求线段不相交,线段可以在圆内也可以在圆外,问是否可以. 思路:假设一条线段,放在圆外是A,放在园内是A',那么两条线段如果必须一 ...
- poj3207 Ikki's Story IV - Panda's Trick 2-sat问题
---题面--- 题意:给定一个圈,m条边(给定),边可以通过外面连,也可以通过里面连,问连完这m条边后,是否可以做到边两两不相交 题解: 将连里面和连外面分别当做一种决策(即每条边都是决策点), 如 ...
- 【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 ...
- 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 ...
- 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 ...
随机推荐
- Ubuntu下安装pip3和Python的第三方库
一.Ubuntu原有环境说明 无论是在服务器上面还是在我们自己的电脑上面,当我们成功安装了Ubuntu系统之后,系统一般情况下会自带Python2.x和Python3.x环境.比如我在自己的阿里云服务 ...
- 关于Star UML
为什么是使用Star UML而不是Visio 2013呢? 以前本人在大学期间使用的Visio 2013来绘制UML的,最近一个星期因为在阅读源码,所以有多学了一门UML绘制工具—Star UML,下 ...
- es6展开运算符
数组的展开合并 现在有两个数组[1, 2, 3, 4]和[5, 6, 7],想要将两个函数拼接成一个新的函数. //es5的写法 let arr1 = [1, 2, 3, 4]; let arr2 = ...
- 基于flash-marker.js 的地图标注闪烁代码调试
修改网上流传的flash-marker.js (function (global, factory) { typeof exports === 'object' && typeof m ...
- selinux详解及配置文件
selinux详解 selinux 的全称是Security Enhance Linux,就是安全加强的Linux.在Selinux之前root账号能够任意的访问所有文档和服务 : 如果某个文件设为7 ...
- Centos 6版本Device eth0 does not seem to be present,delaying initialization.故障处理
1.1 故障现象 2019年06月14日晚上,公司项目组说有台业务服务器连接不上,比较着急,我通过vpn拨入的方式远程登录到管理控制台查看发现网卡没有获取到IP地址,我尝试重启来重新启动,重启的时候 ...
- 关于request.getServletContext()方法报错的问题
可以通过修改pom文件来添加一个javax.servlet-api-3.1.0.jar的jar包,找到你的pom.xml文件添加代码如下: <dependency> <groupId ...
- 浅谈MapReduce工作机制
1.MapTask工作机制 整个map阶段流程大体如上图所示.简单概述:input File通过getSplits被逻辑切分为多个split文件,通通过RecordReader(默认使用lineRec ...
- java 调用第三方系统时的连接代码-记录
前言:该文章主要是总结我在实际工作中遇到的问题,在调取第三方系统的时候出现的问题,算自己的总结.各位博友如果有什么建议或意见欢迎留言指正. 先将准备传入参数 再与第三方系统建立连接 再第三方系统处理后 ...
- Oracle两种临时表的创建与使用详解
ORACLE数据库除了可以保存永久表外,还可以建立临时表temporary tables.这些临时表用来保存一个会话SESSION的数据,或者保存在一个事务中需要的数据.当会话退出或者用户提交comm ...