~~~题面~~~

题意:给定一个圈,m条边(给定),边可以通过外面连,也可以通过里面连,
问连完这m条边后,是否可以做到边两两不相交

题解:

将连里面和连外面分别当做一种决策(即每条边都是决策点),

如果有两条边相冲突,即如果这两条边都连里面就会导致不合法,那就

x --- > y' , y --- > x',

额。。。那怎么判断不合法?

注意到被边u ---> v(u < v)割成两半的分别是:

u ~ v,其他,

一条边不经过这条边的充要条件是:两个端点都在这条边的同一侧。

也就是要么都属于u ~ v,要么都属于其他。

x = x * 2,表示连里面

x = x ^ 1,表示连外面

连边的时候记得双向建边,不然是不可能有大于1的强联通分量的(因为对于任意x点只有出边,任意x'点只有入边)

找到一组冲突的就连x --- > y', y --- > x'.

表示x连里面,y就要放外面,反之同理

 #include<fstream>//文件输入输出
using namespace std;
#define R register int
#define getchar() *o++
#define AC 2200
#define ac 4000100
char READ[],*o=READ;
int n, m, all, tt, cnt;
int low[AC], dfn[AC], belong[AC];
int date[ac], Next[ac], Head[AC], tot;
int s[AC], top;
bool z[AC];
struct node{
int x,y;
}way[AC]; inline int read()
{
int x = ;char c = getchar();
while(c > '' || c < '') c = getchar();
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x;
} inline void add(int f,int w)
{
date[++tot] = w, Next[tot] = Head[f], Head[f] = tot;
date[++tot] = f, Next[tot] = Head[w], Head[w] = tot;//反之也成立,所以要加双向边,不然是不可能有几个连一起的
// printf("%d ---> %d\n",f,w);
} inline void upmin(int &a,int b)
{
if(b < a) a = b;
} void pre()
{
n=read(), m=read(), all = n * ;
for(R i=;i<=m;i++)
{
way[i].x = read(), way[i].y = read();
if(way[i].x > way[i].y) swap(way[i].x, way[i].y);
for(R j=;j<i;j++)//防止重边
{
if(way[j].x > way[i].x && way[j].y < way[i].y) continue;
if(way[j].x < way[i].x && way[j].y < way[i].x) continue;
if(way[j].x > way[i].y && way[j].y > way[i].y) continue;
if(way[j].x < way[i].x && way[j].y > way[i].y) continue;//剩下的就都是冲突的
add(i * , (j * ) ^ );
add(j * , (i * ) ^ );
}
}
} void tarjan(int x)
{
int now;
dfn[x] = low[x] = ++tt;
s[++top] = x, z[x] = true;
for(R i = Head[x]; i ; i = Next[i])
{
now = date[i];
if(!dfn[now])
{
tarjan(now);
upmin(low[x], low[now]);
}
else if(z[now])
upmin(low[x], low[now]);
}
int b = ++cnt;
if(dfn[x] == low[x])
{
while(now = s[top--])
{
belong[now] = b;
z[now] = false;
if(now == x) break;
}
}
} void work()
{
for(R i = ; i <= all; i += )
{
if(belong[i] == belong[i ^ ])
{
printf("the evil panda is lying again\n");
return ;
}
}
printf("panda is telling the truth...\n");
} int main()
{
freopen("in.in","r",stdin);
fread(READ, , , stdin);
pre();
for(R i=;i<=all;i++)
if(!dfn[i]) tarjan(i);
work();
fclose(stdin);
return ;
}

poj3207 Ikki's Story IV - Panda's Trick 2-sat问题的更多相关文章

  1. POJ3207 Ikki's Story IV – Panda's Trick

    Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9426   Accepted: 3465 Description liym ...

  2. 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 ...

  3. poj3207 Ikki’s Story IV – Panda’s Trick

    2-SAT. tarjan缩点.强连通分量的点要选一起选. #include<cstdio> #include<algorithm> #include<cstring&g ...

  4. POJ-3207 Ikki's Story IV - Panda's Trick 2sat

    题目链接:http://poj.org/problem?id=3207 题意:在一个圆圈上有n个点,现在用线把点两两连接起来,线只能在圈外或者圈内,现给出m个限制,第 i 个点和第 j 个点必须链接在 ...

  5. poj3207 Ikki's Story IV - Panda's Trick 2-SAT

    题目传送门 题意:在一个圆上顺时针安放着n个点,给出m条线段连接端点,要求线段不相交,线段可以在圆内也可以在圆外,问是否可以. 思路:假设一条线段,放在圆外是A,放在园内是A',那么两条线段如果必须一 ...

  6. 【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 ...

  7. 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 ...

  8. 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   ...

  9. 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 ...

随机推荐

  1. WeTest功能优化第2期:云真机智能投屏,调试告别鼠标

    第2期功能优化目录 [云真机视频映射]云真机画面本地映射[兼容性测试报告]新增问题机型聚类功能[新增Android9.0]同步上线最新安卓系统 本期介绍的云测产品功能优化,既有重磅级技术突破,也有报告 ...

  2. CentOS 7.2安装11g数据库软件

      Preface       Yesterday I've installed the 11g GI software on CentOS 7.2.But I still encounter som ...

  3. Linux命令应用大词典-第41章 MySQL数据库

    41.1 mysqld_safe:MySQL服务器启动脚本 41.2 mysql_install_db:初始化MySQL数据目录 41.3 mysqlshow:显示MySQL数据库结构 41.4 my ...

  4. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

  5. 爬虫1.1-基础知识+requests库

    目录 爬虫-基础知识+requests库 1. 状态返回码 2. URL各个字段解释 2. requests库 3. requests库爬虫的基本流程 爬虫-基础知识+requests库 关于html ...

  6. 孤荷凌寒自学python第八十一天学习爬取图片1

    孤荷凌寒自学python第八十一天学习爬取图片1 (完整学习过程屏幕记录视频地址在文末) 通过前面十天的学习,我已经基本了解了通过requests模块来与网站服务器进行交互的方法,也知道了Beauti ...

  7. matlab中设置colorbar为几种规定颜色

    我们可以通过修改colormap的值来达到这种目的. 一般来说colormap的值是64*3的矩阵,64代表64种颜色,3列是这种颜色的RGB值,不过归一化了. 如果你想将colorbar颜色设成6种 ...

  8. Paper Reading - Learning like a Child: Fast Novel Visual Concept Learning from Sentence Descriptions of Images ( ICCV 2015 )

    Link of the Paper: https://arxiv.org/pdf/1504.06692.pdf Innovations: The authors propose the Novel V ...

  9. Android开发技巧--Application, ListView排列,格式化浮点数,string.xml占位符,动态引用图片

    一. Application用途 1. Application用途 创建Application时机 : Application在启动的时候会调用Application无参的构造方法创建实例; Appl ...

  10. SOA是什么为什么要面向服务编程

    SOA(面向服务的架构),Service-Oriented Architecture,面向服务的体系结构. 也就是以服务为核心的架构.这里需要理解什么是服务. 比如你有一个读取通知的方法: publi ...