当前位置:网站首页>POJ 3207 Ikki's Story IV – Panda's Trick (2-SAT)
POJ 3207 Ikki's Story IV – Panda's Trick (2-SAT)
2022-07-06 11:47:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
职务地址:找好矛盾关系。矛盾关系是(2,5)和(3,6)这两个仅仅能一个在外边,一个在里边。利用这个矛盾关系来建图。
能够用在外边和里边来当1和0,最后推断每对是否出现矛盾。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define LL __int64
const int INF=0x3f3f3f3f;
int head[1100], cnt, top, ans, index;
int dfn[1100], low[1100], instack[1100], stak[1100], belong[1100];
struct node
{
int u, v, next;
}edge[1000000];
struct N
{
int l, r;
}xian[10000];
void add(int u, int v)
{
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
int pan(N x, N y)
{
if((x.l>y.l&&x.l<y.r&&x.r>y.r)||(x.r>y.l&&x.r<y.r&&x.l<y.l))
return 1;
return 0;
}
void tarjan(int u)
{
dfn[u]=low[u]=++index;
instack[u]=1;
stak[++top]=u;
for(int i=head[u];i!=-1;i=edge[i].next)
{
int v=edge[i].v;
if(!dfn[v])
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(instack[v])
{
low[u]=min(dfn[v],low[u]);
}
}
if(dfn[u]==low[u])
{
ans++;
while(1)
{
int v=stak[top--];
instack[v]=0;
belong[v]=ans;
if(u==v) break;
}
}
}
void init()
{
memset(head,-1,sizeof(head));
cnt=top=ans=index=0;
memset(dfn,0,sizeof(dfn));
memset(instack,0,sizeof(instack));
}
int main()
{
int n, m, i, j;
scanf("%d%d",&n,&m);
init();
for(i=0;i<m;i++)
{
scanf("%d%d",&xian[i].l,&xian[i].r);
if(xian[i].l>xian[i].r) swap(xian[i].l,xian[i].r);
}
for(i=0;i<m;i++)
{
for(j=0;j<i;j++)
{
if(pan(xian[i],xian[j]))
{
add(i<<1,j<<1|1);
add(j<<1,i<<1|1);
add(i<<1|1,j<<1);
add(j<<1|1,i<<1);
//printf("%d %d\n%d %d\n",i<<1,j<<1|1,j<<1,i<<1|1);
}
}
}
for(i=0;i<2*m;i++)
{
if(!dfn[i])
tarjan(i);
}
int flag=0;
for(i=0;i<m;i++)
{
if(belong[i<<1]==belong[i<<1|1])
{
flag=1;
//printf("%d\n",i);
break;
}
}
if(flag) puts("the evil panda is lying again");
else
puts("panda is telling the truth...");
return 0;
}版权声明:本文博主原创文章,博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117134.html原文链接:https://javaforall.cn
边栏推荐
- 系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
- It's enough to read this article to analyze the principle in depth
- MySQL must know and learn
- Elastic search indexes are often deleted [closed] - elastic search indexes gets deleted frequently [closed]
- 凤凰架构2——访问远程服务
- Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting
- Interpretation of Dagan paper
- Don't miss this underestimated movie because of controversy!
- Use of map (the data of the list is assigned to the form, and the JSON comma separated display assignment)
- 121. 买卖股票的最佳时机
猜你喜欢
随机推荐
思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
[玩转Linux] [Docker] MySQL安装和配置
CPU负载很低,loadavg很高处理方法
Reflection and illegalaccessexception exception during application
Unbalance balance (dynamic programming, DP)
力扣101题:对称二叉树
Swagger2 reports an error illegal DefaultValue null for parameter type integer
Don't miss this underestimated movie because of controversy!
Dark horse -- redis
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
Interview assault 63: how to remove duplication in MySQL?
MySQL information schema learning (II) -- InnoDB table
map的使用(列表的数据赋值到表单,json逗号隔开显示赋值)
How to access localhost:8000 by mobile phone
社招面试心得,2022最新Android高频精选面试题分享
CCNP Part 11 BGP (III) (essence)
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
从sparse.csc.csr_matrix生成邻接矩阵







