【POJ】3207 Ikki's Story IV - Panda's Trick
http://poj.org/problem?id=3207
题意:一个圆上顺时针依次排列着标号为1~n的点,这些点之间共有m条边相连,每两个点只能在圆内或者圆外连边。问是否存在这些边不相交的方案。(n<=1000, m<=500)
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <iostream>
- using namespace std;
- #define zero(x) ((x)<<1)
- #define one(x) (zero(x)|1)
- const int N=1005;
- struct E { int next, to; }e[(N*N)<<2];
- int ihead[N], cnt, tot, num, FF[N], LL[N], vis[N], s[N], top, p[N], X[N], Y[N], n, m;
- void add(int x, int y) { e[++cnt]=(E){ihead[x], y}; ihead[x]=cnt; }
- void tarjan(int x) {
- FF[x]=LL[x]=++tot; s[++top]=x; vis[x]=1;
- for(int i=ihead[x]; i; i=e[i].next) {
- if(!FF[e[i].to]) tarjan(e[i].to), LL[x]=min(LL[x], LL[e[i].to]);
- else if(vis[x]) LL[x]=min(LL[x], FF[e[i].to]);
- }
- if(FF[x]==LL[x]) {
- int y;
- ++num;
- do {
- y=s[top--];
- vis[y]=0;
- p[y]=num;
- } while(x!=y);
- }
- }
- bool work() {
- int mm=m<<1;
- for(int i=0; i<mm; ++i) if(!FF[i]) tarjan(i);
- for(int i=0; i<mm; i+=2) if(p[i]==p[i+1]) return false;
- return true;
- }
- void clr() {
- int mm=m<<1;
- memset(ihead, 0, sizeof(int)*(mm));
- memset(FF, 0, sizeof(int)*(mm));
- memset(p, 0, sizeof(int)*(mm));
- cnt=tot=top=num=0;
- }
- int main() {
- while(~scanf("%d%d", &n, &m)) {
- for(int i=0; i<m; ++i) { scanf("%d%d", &X[i], &Y[i]); if(X[i]>Y[i]) swap(X[i], Y[i]); }
- for(int i=0; i<m; ++i) {
- int a=X[i], b=Y[i];
- for(int j=0; j<m; ++j) if(i!=j) {
- int c=X[j], d=Y[j];
- if((a<c && c<b && (a>d || d>b)) || (a<d && d<b && (a>c || c>b)))
- add(zero(i), one(j)), add(one(i), zero(j));
- }
- }
- if(!work()) puts("the evil panda is lying again");
- else puts("panda is telling the truth...");
- clr();
- }
- return 0;
- }
容易发现一条边连圆内那么在圆内的其它边与这条边有交的那么我们就连x->y'。如果一条边连在圆外那么圆外的其他边有交的我们就连x'->y。
那么搞搞就行辣= =
(现在写tarjan缩点辣~具体算法看论文 伍昱:《由对称性解2-SAT问题》
【POJ】3207 Ikki's Story IV - Panda's Trick的更多相关文章
- 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问题)
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 ...
- 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+tarjan】
注意到相交的点对一定要一里一外,这样就变成了2-SAT模型 然后我建边的时候石乐志,实际上不需要考虑这个点对的边是正着连还是反着连,因为不管怎么连,能相交的总会相交,所以直接判相交即可 然后tarja ...
- 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模板题
题意: 平面上,一个圆,圆的边上按顺时针放着n个点.现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接.给你的信息中,每个点最多只会连接的一条边.问能不能连接这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 ...
- 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 Ikk ...
随机推荐
- gcc【数学几何】
GCC Time Limit: 1000MS Memory limit: 65536K 题目描述 The GNU Compiler Collection (usually shortened to G ...
- SQLAlchemy ORM高级查询之过滤,排序
order_by,filter的语法. 用久了才会熟悉. Session = sessionmaker(bind=engine) session = Session() print(session.q ...
- POJ3294 Life Forms(后缀数组)
引用罗穗骞论文中的话: 将n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组.然后二分答案,用和例3 同样的方法将后缀分成若干组,判断每组的后缀是否出现在不小于k 个的原串中 ...
- php array_intersect() 和 array_diff() 函数
在PHP中,使用 array_intersect 求两个数组的交集比使用 array_diff 求同样两个数组的并集要快. 如果要求数组 $a 与数组 $b 的差集的个数,应该使用 count($a) ...
- C# 创建Windows Service
当我们需要一个程序长期运行,但是不需要界面显示时可以考虑使用Windows Service来实现.这篇博客将简单介绍一下如何创建一个Windows Service,安装/卸载Windows Servi ...
- 【leetcode】Remove Duplicates from Sorted Array
题目描述: Given a sorted array, remove the duplicates in place such that each element appear only once a ...
- Zero Copy 简介
转自:http://blog.csdn.net/zzz_781111/article/details/7534649 许多web应用都会向用户提供大量的静态内容,这意味着有很多data从硬盘读出之后, ...
- MySQL模糊查询:LIKE模式和REGEXP模式
MySQL模糊查询提供了两种模式:LIKE模式和REGEXP模式. LIKE模式 LIKE模式是使用的LIKE 或 NOT LIKE 比较运算符进行模糊查询. SELECT 字段 FROM 表 WHE ...
- 【SSH】 之 Struts2
(一)Struts2是什么? Struts2是一个基于MVC设计模式的Web应用框架,它本质上相当于一个servlet,在MVC设计模式中,Struts2作为控制器(Controller)来建立模型与 ...
- MFC中afx_msg是什么,afx_msg void function()是什么意思
应用程序框架产生的消息映射函数例如:afx_msg void OnBnClickedButton1(); 其中 afx_msg为消息标志,它向系统声明:有消息映射到函数实现体:而在map宏定义中,就有 ...