poj 3207 Ikki's Story IV - Panda's Trick
来源:互联网 发布:域名转出 费用 编辑:程序博客网 时间:2024/05/16 10:09
圆上依次从0到n-1标记点,给出m个边,问当这m个边连好之后,是否有相交的
边有园外园内之分……
2-SAT
#include<iostream>#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<algorithm>using namespace std;const int MAXN = 510;struct twosat{ int n,c; vector<int> g[MAXN<<1]; bool mark[MAXN<<1]; int s[MAXN<<1]; bool dfs(int x) { int i; if (mark[x^1]) return 0; if (mark[x]) return 1; mark[x] = 1; s[c++] = x; for (i = 0; i < g[x].size(); i++) if (!dfs(g[x][i])) return 0; return 1; } void init(int n) { int i,t=n<<1; this->n = n; for (i = 0; i < t; i++) g[i].clear(); memset(mark, 0, sizeof(mark)); } void add_clause(int x, int xval, int y, int yval) { x = x * 2 + xval; y = y * 2 + yval; g[x^1].push_back(y); g[y^1].push_back(x); } bool solve() { int i,t=n<<1; for (i = 0; i < t; i += 2) if (!mark[i] && !mark[i + 1]) { c = 0; if (!dfs(i)) { while (c > 0) mark[s[--c]] =0; if (!dfs(i + 1)) return 0; } } return 1; } }ender;struct seg{int s,e;}in[510];bool iscross(seg a,seg b,int flag1,int flag2){if(flag1!=flag2)return 0;if(a.s<b.s&&b.s<a.e&&(b.e<a.s||b.e>a.e))return 1;if(b.s<a.s&&a.s<b.e&&(a.e<b.s||a.e>b.e))return 1;return 0;}int main(){int i,j,n,m,x,y;cin>>n>>m;for(i=0;i<m;i++){cin>>in[i].s>>in[i].e;if(in[i].s>in[i].e)swap(in[i].s,in[i].e);}ender.init(m);for(i=0;i<m;i++)for(j=i+1;j<m;j++)for(x=0;x<2;x++)for(y=0;y<2;y++)if(iscross(in[i],in[j],x,y))ender.add_clause(i,x,j,y);if(ender.solve())cout<<"panda is telling the truth..."<<endl;elsecout<<"the evil panda is lying again"<<endl;return 0;}
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 andm (n ≤ 1,000, m ≤ 500). The following m lines each contain two integersai and bi, which denote the endpoints of theith 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...
Source
- 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
- poj 3207 Ikki's Story IV - Panda's Trick
- Ikki's Story IV - Panda's Trick
- poj Ikki's Story IV - Panda's Trick (2-sat)
- Pku 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
- poj 3207 Ikki's Story IV - Panda's Trick 2-sat+建图
- poj 3207 Ikki's Story IV - Panda's Trick#2-sat
- 陈天桥或未完全退出盛大游戏
- iOS开发 - post / get 详解
- NLTK 学习笔记(4)
- ASCII与unicode
- Java当中的数组
- poj 3207 Ikki's Story IV - Panda's Trick
- XCode 快捷键, MAC 快捷键
- 14周项目6 读程序
- 有关快速排序的心情
- linux(CentOS)忘记root密码解决办法
- 《老友记》vs《新旧走遍美国》
- poj 3177 Redundant Paths
- struts2 从一个action 跳转到另一个action的两种方法
- H.264编码之DCT变换公式推导