POJ 3207:Ikki's Story IV
来源:互联网 发布:淘宝页面找不 编辑:程序博客网 时间:2024/05/29 05:57
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 20 13 2
Sample Output
panda is telling the truth...
题意:
一个圆边上有n个点(标号顺时针),现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接。输入保证每个点最多只会连接的一条边。问有没有方法连接这m条边,使这些边都不相交
建图方式参考
http://blog.csdn.net/jaihk662/article/details/71087449
直接强联通分量,若某个强联通分量中的一个点要选,那么这个强联通分量中的所有点都必选
如果某个点对中的两个点属于同一强联通分量,那么无解,否则一定有解
复杂度O(n)
#include<stdio.h>#include<string.h>#include<algorithm>#include<stack>#include<vector>using namespace std;vector<int> G[2017];stack<int> st;typedef struct{int x;int y;}Res;Res s[1005];int t, num, time[1005], low[1005], vis[1005], fa[1005];void tarjan(int u){int v, i;vis[u] = 1;st.push(u);time[u] = low[u] = ++t;for(i=0;i<G[u].size();i++){v = G[u][i];if(time[v]==0){tarjan(v);low[u] = min(low[u], low[v]);}else if(vis[v])low[u] = min(low[u], time[v]);}if(time[u]==low[u]){num++;while(1){ v = st.top();st.pop();vis[v] = 0;fa[v] = num;if(v==u)break;}}}int main(void) {int i, j, ans, n;scanf("%*d%d", &n);for(i=1;i<=n;i++){scanf("%d%d", &s[i].x, &s[i].y);s[i].x++; s[i].y++;if(s[i].x>s[i].y)swap(s[i].x, s[i].y);}for(i=1;i<=n*2;i++)G[i].clear();for(i=1;i<=n;i++){for(j=i+1;j<=n;j++){if((s[i].x<=s[j].x && s[i].y>=s[j].x && s[i].y<=s[j].y) || (s[i].x>=s[j].x && s[i].x<=s[j].y && s[i].y>=s[j].y)){G[i].push_back(j+n);G[j].push_back(i+n);G[i+n].push_back(j);G[j+n].push_back(i);}}}n = 2*n; for(i=1;i<=n;i++){if(time[i]==0)tarjan(i);}ans = 1;for(i=1;i<=n/2;i++){ if(fa[i]==fa[i+n/2])ans = 0;}if(ans)printf("panda is telling the truth...\n");elseprintf("the evil panda is lying again\n");return 0;}
- poj 3207 Ikki's Story IV
- POJ 3207:Ikki's Story IV
- POJ 3207 Ikki's Story IV
- POJ 3207 Ikki's Story IV
- POJ 3207 Ikki's Story IV
- [POJ 3207] Ikki's Story IV
- POJ 3207 Ikki's Story IV
- POJ 3207 Ikki's Story IV
- POJ 3207 Ikki's Story IV-Panda's Trick
- poj 3207 Ikki's Story IV - Panda's Trick
- poj 3207 Ikki's Story IV - Panda's Trick
- poj 3207 Ikki's Story IV - Panda's Trick
- POJ 3207 Ikki's Story IV - Panda's Trick
- POJ 3207 Ikki's Story IV - Panda's Trick
- poj 3207 Ikki's Story IV - Panda's Trick
- POJ 3207 Ikki's Story IV - Panda's Trick
- poj 3207 Ikki's Story IV - Panda's Trick
- 【POJ 3207】Ikki's Story IV - Panda's Trick
- input,checkbox启用禁用
- react demo11 (添加组件事件处理)
- react整理二阶段学习笔记
- "=="和 equals 方法究竟有什么区别?
- 向量的叉积及其应用
- POJ 3207:Ikki's Story IV
- Predict the Winner
- 1009. Product of Polynomials (25)[C语言]
- 算法学习笔记--贪婪算法
- java 判断一个数组中的数值是否连续相邻
- C++:虚基类详解
- 关于学习 unity3D 的知识预储备
- 对pair进行排序
- 1011. World Cup Betting (20)[C语言]