POJ 3207
还是那句话,做2SAT题时,找出矛盾点基本上可解了。这道题也是这样
题意是说给出一个圆上的 n 个点(0~n-1编号),然后在指定的 m 对点之间各连一条线(可以在圆内,也可以在圆外,可以是曲线,这点真心坑爹,开始一直木有看明白),然后问你是否能使这些线都不相交
当两条线在同一边会有交点时,即会有矛盾,建图加边。
对于那些没有交点即没有矛盾的边,直接忽略就好,因为边的含义是“必须”。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; const int MAXN=;
const int MAXM=;
int n,m;
struct d{
int u,v;
}sv[];
int dfn[MAXN],low[MAXN],st[MAXN],tot,stop,pat,indx,belong[MAXN];
bool stack[MAXN];
struct e{
int u,v;
int next;
}edge[MAXM];
int head[MAXN]; void addedge(int u,int v){
edge[tot].u=u;
edge[tot].v=v;
edge[tot].next=head[u];
head[u]=tot++;
} void exch(int &x,int &y){
if(x>y){
int tmp=y;
y=x;
x=tmp;
}
} bool sure(int i,int k){
int u=sv[k].u;
int v=sv[k].v;
int p=sv[i].u;
int q=sv[i].v;
if(p>=u&&p<=v&&q>=u&&q<=v)
return false;
if(p>=v) return false;
if(q<=u) return false;
if(p<=u&&q>=v) return false;
return true;
} void tarjan(int u){
dfn[u]=low[u]=++indx;
stack[u]=true;
st[stop++]=u;
int v;
for(int e=head[u];e!=-;e=edge[e].next){
v=edge[e].v;
if(dfn[v]==){
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(stack[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u]){
pat++;
do{
v=st[--stop];
belong[v]=pat;
stack[v]=false;
}while(u!=v);
}
} int main(){
int u,v;
while(scanf("%d%d",&n,&m)!=EOF){
tot=indx=pat=stop=;
for(int i=;i<m*;i++){
dfn[i]=low[i]=belong[i]=;
stack[i]=false; head[i]=-;
} for(int i=;i<m;i++){
scanf("%d%d",&sv[i].u,&sv[i].v);
exch(sv[i].u,sv[i].v);
if(i>){
for(int k=;k<i;k++){
if(sure(i,k)){
addedge(*i,*k+);
addedge(*k,*i+);
addedge(*i+,*k);
addedge(*k+,*i);
}
}
}
} for(int i=;i<*m;i++)
if(dfn[i]==)
tarjan(i); bool flag=true;
for(int i=;i<m;i++){
if(belong[i*]==belong[*i+]){
flag=false;
printf("the evil panda is lying again\n");
break;
}
}
if(flag)
printf("panda is telling the truth...\n");
}
return ;
}
POJ 3207的更多相关文章
- POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT)
职务地址:id=3207">POJ 3207 找好矛盾关系.矛盾关系是(2,5)和(3,6)这两个仅仅能一个在外边,一个在里边.利用这个矛盾关系来建图. 能够用在外边和里边来当1和0, ...
- 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 ...
- 2-SAT的小总结(POJ 3683 POJ 3207)
记住几个最重要的公式: xANDy=0<=>(x=>y′)AND(y=>x′) xANDy=1<=>(x′=>x)AND(y′=>y) xORy=0&l ...
- POJ 3207 Ikki's Story IV - Panda's Trick(2-sat)
POJ 3207 Ikki's Story IV - Panda's Trick id=3207" target="_blank" style=""& ...
- 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 ...
- [2-SAT] poj 3207 Ikki's Story IV - Panda's Trick
题目链接: id=3207">http://poj.org/problem? id=3207 Ikki's Story IV - Panda's Trick Time Limit: 1 ...
- POJ 3207 【2-SAT入门题 + 强连通分量】
这道题是我对于2-SAT问题的入门题:http://poj.org/problem?id=3207 一篇非常非常非常好的博客,很详细,认真看一遍差不多可以了解个大概:https://blog.csdn ...
- 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(2-SAT+SCC)
传送门:Problem 3207 https://www.cnblogs.com/violet-acmer/p/9769406.html 难点: 题意理解. 题意: 平面上有一个圆,圆上有n个点(分别 ...
- 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 ...
随机推荐
- 洛谷P2593 [ ZJOI 2006 ] 超级麻将 —— DP
题目:https://www.luogu.org/problemnew/show/P2593 DP的话,考虑到当前这一位只跟前两位有关,所以记录一下这3位的状态就行: 于是一开始记录的第 i 位,i- ...
- myeclipse视图布局恢复
使用Windows 菜单下的 Reset Perspective
- VS2010中文注释带红色下划线的解决方法
环境:Visual Studio 2010 问题:代码中出现中文后会带下划线,很多时候感觉很不舒服.找了很久的原因没找到,后来无意中在VisualAssist X里找到了解决办法. 1.安装完Visu ...
- layui日期输入框
<div class="layui-form-item"> <label class="layui-form-label& ...
- 使用ZeppelinHub来存储和展示ZeppelinNoteBook
0.序 说实在的这个功能太赞了 在一开始接触的时候不知道有这个功能,我尝试做一下配置,发现非常的棒. 棒的原因有两点: 可以在随时随地有互联网的地方访问自己的ZeppelinHub来查看Zeppeli ...
- Java 类加载器及加载Class字节码
参考来源:http://www.cnblogs.com/fingerboy/p/5456371.html java笔记--理解java类加载器以及ClassLoader类 参考来源:htt ...
- OneThink管理平台 ,登录后台一直提示验证码错误
可能是数据库的错.上传到服务器以后要改2个地方的配置,\Application\Common\Conf\config.php(整站公用配置文 件),\Application\User\Conf\con ...
- HTML 5的基本标签
1. 文件开始标签<html> 在任何的一个HTML文件里,最先出现的HTML标签就是<html>,它用于表示该文件是以超文本标识语言(HTML)编写的.<html&g ...
- 修改Switch 的颜色
1:效果图 2:布局 <Switch android:id="@+id/switch_bg" style="@style/switchStyle" and ...
- Scala: Types of a higher kind
One of the more powerful features Scala has is the ability to generically abstract across things tha ...