POJ 3207 Ikki's Story IV - Panda's Trick
Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 7296 | Accepted: 2705 |
Description
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.
Input
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
Output a line, either “panda is telling the truth...
” or “the evil panda is lying again
”.
Sample Input
4 2
0 1
3 2
Sample Output
panda is telling the truth...
Source
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#pragma comment(linker, "/STACK:10240000000000,10240000000000")
using namespace std;
typedef long long LL ;
const int Max_N= ;
const int Max_M= ;
int id ;
int vec[Max_N] ,mystack[Max_N] ,top;
int low[Max_N] ,dfn[Max_N] ,idx ,num ;
bool instack[Max_N] ;
int belong[Max_N] ; //belong[i] ,i为哪个联通分量
//int sum[Max_N] ; //缩点后每个联通分量中点的个数
struct Edge{
int v ;
int next ;
};
Edge edge[Max_M] ;
inline void add_edge(int u,int v){
edge[id].v=v ;
edge[id].next=vec[u] ;
vec[u]=id++ ;
}
void tarjan(int u){
low[u]=dfn[u]=idx++ ;
mystack[++top]=u ;
instack[u]= ;
for(int e=vec[u];e!=-;e=edge[e].next){
int v=edge[e].v ;
if(dfn[v]==-){
tarjan(v) ;
low[u]=Min(low[u],low[v]) ;
}
else if(instack[v])
low[u]=Min(low[u],dfn[v]) ;
}
if(low[u]==dfn[u]){
int v ;
num++ ;
do{
v=mystack[top--] ;
instack[v]= ;
belong[v]=num ;
// sum[num]++ ;
}while(v!=u) ;
}
}
void init(){
idx= ;
top=- ;
num= ;
id=;
memset(dfn,-,sizeof(dfn)) ;
memset(vec,-,sizeof(vec)) ;
memset(instack,,sizeof(instack)) ;
// memset(sum,0,sizeof(sum)) ;
}
int N ;
int judge(){
for(int i=;i<=N;i++){
if(belong[i]==belong[i+N])
return ;
}
return ;
}
struct Line{
int s ;
int t ;
};
Line L[Max_N] ;
int cross(Line A ,Line B){
if(B.s<A.s&&A.s<B.t&&B.t<A.t)
return ;
if(A.s<B.s&&B.s<A.t&&A.t<B.t)
return ;
return ;
}
int main(){
int m ;
while(scanf("%d%d",&m,&N)!=EOF){
for(int i=;i<=N;i++)
scanf("%d%d",&L[i].s,&L[i].t) ;
init() ;
for(int i=;i<=N;i++)
for(int j=i+;j<=N;j++){
if(cross(L[i],L[j])){
add_edge(i,j+N) ;
add_edge(j,i+N) ;
add_edge(i+N,j) ;
add_edge(j+N,i) ;
}
}
for(int i=;i<=*N;i++){
if(dfn[i]==-)
tarjan(i) ;
}
if(judge())
puts("panda is telling the truth...") ;
else
puts("the evil panda is lying again") ;
}
return ;
}
POJ 3207 Ikki's Story IV - Panda's Trick的更多相关文章
- 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 (2-SAT)
http://poj.org/problem?id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 13 ...
- 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 ...
- POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT,基础)
题意: 有一个环,环上n个点,现在在m个点对之间连一条线,线可以往圆外面绕,也可以往里面绕,问是否必定会相交? 思路: 根据所给的m条边可知,假设给的是a-b,那么a-b要么得绕环外,要么只能在环内, ...
- poj 3207 Ikki's Story IV - Panda's Trick【2-SAT+tarjan】
注意到相交的点对一定要一里一外,这样就变成了2-SAT模型 然后我建边的时候石乐志,实际上不需要考虑这个点对的边是正着连还是反着连,因为不管怎么连,能相交的总会相交,所以直接判相交即可 然后tarja ...
- POJ 3207 Ikki's Story IV - Panda's Trick 2-sat模板题
题意: 平面上,一个圆,圆的边上按顺时针放着n个点.现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接.给你的信息中,每个点最多只会连接的一条边.问能不能连接这m条边,使这 ...
- 【POJ】3207 Ikki's Story IV - Panda's Trick
http://poj.org/problem?id=3207 题意:一个圆上顺时针依次排列着标号为1-n的点,这些点之间共有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 ...
- Ikki's Story IV - Panda's Trick POJ - 3207(水2 - sat 在圈内 还是 在圈外)
题意: 就是一个圈上有n个点,给出m对个点,这m对个点,每一对都有一条边,合理安排这些边在圈内或圈外,能否不相交 解析: 我手残 我手残 我手残 写一下情况 只能是一个在圈外 一个在圈内 即一个1一个 ...
随机推荐
- java mail使用中遇到的550类型错误
前言 首先,需要说明的是,本错误来自于一个简单的基于java mail的api程序,邮件服务器是163的SMTP,即smtp.163.com. 程序 需要说明一下,下面这个程序,是来自于网络上,本人为 ...
- .NET和java的RSA互通,仅此而已
.NET和java的RSA互通,仅此而已 在开始这篇文章之前,先请读者朋友阅读老唐的这两篇文章: 1.Java与.Net环境下RSA加密解密交互不成功的问题解决 2.Java与.Net环境下RSA加密 ...
- 解决方案:将已存在的项目 添加到 tfs解决方案中的时候 出现:新项目不能成功加入源码控制
遇到此问题 可能是因为你的 解决方案文件 没有正确与 tfs服务器绑定导致的 解决方式是: 在打开任意一个源码文件的时候,打开 vs2013的 文件>> Go to File->So ...
- Bind 跨域名别名解析的问题
我有一个域名 aaa.net 已经生效 ,并且下面有 xx的 A记录:现在我还有一个 aaa.com域名 ,我想用 别名方式把它下面 某个 记录以别名方式解析到 xx.aaa.net上去.应该在aaa ...
- WINDOWS黑客基础(4):查找进程运行的基址
从WINDOWS VISITA开始以后,windows已经开始支持随机基址的关系,也就是说以前我们的进程基址都是从0x40000开始的,如果一个变量在我们第一次运行的时候地址为0x50000,那么以后 ...
- MSSQL update 多表关联更新
update tMeter set 字段= t.源自段 from ( select * from 源表信息 ) t where 关联条件 实际demo: UPDATE dbo.WX_TWODIMENC ...
- 像装软件一样装系统 Win8下怎么装Win7
像装软件一样装系统 Win8下怎么装Win7 首先,你需要一个Windows7的ISO镜像文件,非ghost版本 一般选中ISO文件,点反键在弹出菜单中以“装载”或“window资源管理器”方式打开 ...
- [linux basic 基础]----同步互斥量
互斥量,运行程序元锁住某个对象,使得每次只能有一个线程访问它:为了控制对关键代码的访问,必须在进入这段代码之前锁住一个互斥量,然后在完成操作之后解锁它 :基本函数与用于信号量的函数非常相似#inclu ...
- 【转】SQL Server sql_variant 类型的比较
sql_variant 类型用于存储SQL SERVER中支持的各种数据类型. 为了进行 sql_variant 比较,SQL Server 数据类型层次结构顺序划分为多个数据类型系,sql_vari ...
- 四层LB和七层LB
总结: 基于MAC地址玩的是二层(虚拟MAC地址接收请求,然后再分配到真实的MAC地址), 基于IP地址玩的是三层(虚拟IP地址接收请求,然后再分配到真实的IP地址), 基于IP地 ...