当前位置:网站首页>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
边栏推荐
- Druid database connection pool details
- Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
- IC设计流程中需要使用到的文件
- 【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
- 反射及在运用过程中出现的IllegalAccessException异常
- LeetCode_双指针_中等_61. 旋转链表
- 《数字经济全景白皮书》保险数字化篇 重磅发布
- GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions
- Classic 100 questions of algorithm interview, the latest career planning of Android programmers
- Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
猜你喜欢
It's enough to read this article to analyze the principle in depth
A method of removing text blur based on pixel repair
It's super detailed in history. It's too late for you to read this information if you want to find a job
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
Leetcode 30. Concatenate substrings of all words
Low CPU load and high loadavg processing method
Don't miss this underestimated movie because of controversy!
Interpretation of Dagan paper
《数字经济全景白皮书》保险数字化篇 重磅发布
【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
随机推荐
思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
Unbalance balance (dynamic programming, DP)
Simple application of VBA script in Excel
通俗的讲解,带你入门协程
Benefit a lot, Android interview questions
Mysql Information Schema 学习(一)--通用表
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
[pytorch] yolov5 train your own data set
Systematic and detailed explanation of redis operation hash type data (with source code analysis and test results)
swagger2报错Illegal DefaultValue null for parameter type integer
Mysql Information Schema 學習(一)--通用錶
Leetcode 30. 串联所有单词的子串
[translation] supply chain security project in toto moved to CNCF incubator
【翻译】供应链安全项目in-toto移至CNCF孵化器
[玩转Linux] [Docker] MySQL安装和配置
Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
关于图像的读取及处理等
350. 两个数组的交集 II
Hudi vs Delta vs Iceberg
Dark horse -- redis