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一个 ...
随机推荐
- javascript util.js
//根据Id获得页面元素 function $(para) { return document.getElementById(para);} //创建一个新的元素function createE ...
- C#写入登陆Cookies
protected void Page_Load(object sender, EventArgs e) { //打开登录页面时获取客户端cookie值并写入前台控件中 HttpCookie cook ...
- SPOJ #11 Factorial
Counting trailing 0s of n! It is not very hard to figure out how to count it - simply count how many ...
- 【centos7】设置开机自启动服务--systemd
centos7使用systemd管理开机自启动服务,不提倡rc.local. 假设现在有2个服务,分别为: my111: my222: 希望在开机时自动启动my222服务,但是my222启动需要my1 ...
- bzoj2467: [中山市选2010]生成树
Description 有一种图形叫做五角形圈.一个五角形圈的中心有1个由n个顶点和n条边组成的圈.在中心的这个n边圈的每一条边同时也是某一个五角形的一条边,一共有n个不同的五角形.这些五角形只在五角 ...
- flash builder 启动ios模拟器失败是什么原因?
参考知乎:http://www.zhihu.com/question/22537362 在mac os设置-安全性与隐私-隐私-辅助功能 找到flash bulder 打上前面的勾,如下图:
- Javascript之UI线程与性能优化
在浏览器中,Javascript执行与UI更新是发生在同一个进程(浏览器UI线程)中的.UI线程的工作基于一个简单的队列系统,任务会被保存到队列中直到进程空闲时被提取出来执行.所以Javascript ...
- (WPF) MVVM: 动态添加控件及绑定。
比如需要显示一个键盘,里面有各个按键.实现的效果如下: 之前的思路,就是建立一个singleKey的控件,然后在后台用代码动态的添加到父控件里去, 再用代码在后台进行绑定. 这种实现方法并不是真正的M ...
- Spark作业调度
Spark在任务提交时,主要存在于Driver和Executor的两个节点. (1)Driver的作用: 用于将所有要处理的RDD的操作转化为DAG,并且根据RDD DAG将JBO分割为多个Stage ...
- matlab R2016b 设置界面为英文
对于matlab的使用,最好还是使用英文好.这样既能让你熟悉直接的英文解释,也能学习一下英语. 对于中文版的matlab,默认的Matlab安装是中文,所以这里存在安装matlab后设置语言的需要. ...