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 ...
随机推荐
- kubernetes-ingress(十)
ingress https://kubernetes.io/docs/concepts/services-networking/ingress/ pod与ingress的关系 •通过label-sel ...
- 《坐热板凳》第九次团队作业:Beta冲刺与验收准备(第一天)
<坐热板凳>第九次团队作业:Beta冲刺与验收准备 项目 内容 这个作业属于哪个课程 http://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https ...
- 分享12款最佳的Bootstrap设计工具
设计师总会渴望有一些新奇有趣的设计工具来提高工作效率,而Bootstrap就是您的不二选择.2013年Bootstrap得到了广泛普及, 它是开发者较为常用的框架之一,本文我们将分享12款最佳的Boo ...
- Linux-准备工作
首先安装一个box,安装一个centos7,然后就是xshell,接下来就是 查看ip ifconfig ip addr vi /etc/sysconfig/network-scripts/ifcfg ...
- 使用FileSystem类进行文件读写及查看文件信息
使用FileSystem类进行文件读写及查看文件信息 在这一节我们要深入了解Hadoop的FileSystem类——这是与与hadoop的文件系统交互的重要接口.虽然我们只是着重于HDFS的实现, ...
- [转]using components in Cakephp 2+ Shell
<?php App::uses('AppShell', 'Console/Command'); App::uses('ComponentCollection', 'Controller'); A ...
- Excel动画教程50例(三)
Excel动画教程50例(三) 31.Excel自定输入数据下拉列表 32.Excel正确输入身份证号码 33.Excel数据排序操作 34.Excel数据表格中如何将姓名信息按笔画排列 35.Exc ...
- leetcode 【 Convert Sorted List to Binary Search Tree 】python 实现
题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height ...
- 第九届极客大挑战 部分WP
CODE 和0xpoker分0day 百度 取石子游戏. https://blog.csdn.net/qq_33765907/article/details/51174524 已经说得很详细了,慢慢来 ...
- python(或BAT脚本)自动执行adb shell以后的命令
最近在用python做一个小工具,自动执行一些adb shell命令,使用subprocess.Popen来实现. 不过遇到个问题就是执行adb shell后就无法执行后面adb shell里的命 ...