~~~题面~~~

题意:给定一个圈,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. SpringBoot-02:SpringBoot中的POM文件详细解释

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 我把pom文件,以及它的详细解释发出来 <?xml version="1.0" en ...

  2. springBoot 自定义redisTemplate

    package com.atirm.mybatismutiplesource.config.RedisConfig; import com.atirm.mybatismutiplesource.ent ...

  3. 关于BLOB/TEXT字段存储设计及性能的简单研究

    简单研究了一下BLOB/TEXT字段对数据库性能的影响,得到一个大概的结论:(未验证) 无论MySQL还是MSSQL,都可以通过把BLOB/TEXT数据存储在行外的方式提高性能 把BLOB/TEXT字 ...

  4. libevent学习六(Connect listeners )

      创建与释放 //backlog需要查询平台说明,在linux2.2以后 backlog就变成了已完成连接但未accept的队列的最大值(原来是处于syn状态的,现在换成sysctl 控制的参数tc ...

  5. poj3984迷宫问题(dfs+stack)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35426   Accepted: 20088 Descriptio ...

  6. sql注入记录------类型转换错误---convert()函数,一句话图片马制作

    sql注入在联合查询是出现一下错误查不到数据 Illegal mix of collations for operation 'UNION' 用convert() 转换编码为utf8 或者big5 就 ...

  7. 180609-Spring之事件驱动机制的简单使用

    文章链接:https://liuyueyi.github.io/hexblog/hexblog/2018/06/09/180609-Spring之事件驱动机制的简单使用/ Spring之事件驱动机制的 ...

  8. 爬虫——URL模块爬取糗事百科段子

    最简单的爬取网页找有用信息,难点应该是正则锁定有用信息部分,看了一些其他大神的正则,最后还是决定按照自己理解写一个,果然我头脑相对简单,写出来的粗糙而易理解,也完成了自己想要的需求,就这样了~ # - ...

  9. 韦大仙--python对文件操作

    文件操作: 对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 现有文件如下 Somehow, it seems the love I knew was alwa ...

  10. wordlist 4

    wordlist 4 desolate 啥啥啥lete adj. 荒凉的:无人烟的 repression depression n. 抑制,[心理] 压抑:镇压 / n. 沮丧:忧愁:抑郁症: spe ...