当前位置:网站首页>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 19:50:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
Position address : Find contradictions . The contradiction is (2,5) and (3,6) Only one of these two can be outside , One is inside . Use this contradictory relationship to build a map .
It can be used outside and inside as 1 and 0, Finally, infer whether each pair has contradictions .
The code is as follows :
#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;
}Copyright notice : This article is the original article of the blogger , Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117134.html Link to the original text :https://javaforall.cn
边栏推荐
- Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
- POJ1149 PIGS 【最大流量】
- 在解决了 2961 个用户反馈后,我做出了这样的改变...
- Classic 100 questions of algorithm interview, the latest career planning of Android programmers
- Leetcode 30. 串联所有单词的子串
- [play with Linux] [docker] MySQL installation and configuration
- PHP与EXCEL PHPExcel
- Vscode debug run fluent message: there is no extension for debugging yaml. Should we find yaml extensions in the market?
- HDU 1026 search pruning problem within the labyrinth of Ignatius and the prince I
- Logstash expressway entrance
猜你喜欢

【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。

Leetcode 30. 串联所有单词的子串

MySQL information schema learning (I) -- general table

Zero foundation entry polardb-x: build a highly available system and link the big data screen
腾讯架构师首发,2022Android面试笔试总结

在解决了 2961 个用户反馈后,我做出了这样的改变...

Example of applying fonts to flutter

如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!

After solving 2961 user feedback, I made such a change

新一代垃圾回收器—ZGC
随机推荐
[translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
Transformer model (pytorch code explanation)
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
凤凰架构2——访问远程服务
LeetCode_格雷编码_中等_89.格雷编码
蓝桥杯 微生物增殖 C语言
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
PHP与EXCEL PHPExcel
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
Leetcode 30. 串联所有单词的子串
【翻译】供应链安全项目in-toto移至CNCF孵化器
1805. Number of different integers in the string
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
深入浅出,面试突击版
Logstash expressway entrance
In depth analysis, Android interview real problem analysis is popular all over the network
Pay attention to the partners on the recruitment website of fishing! The monitoring system may have set you as "high risk of leaving"
LeetCode_双指针_中等_61. 旋转链表
深度剖析原理,看完这一篇就够了
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)