当前位置:网站首页>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
边栏推荐
- Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
- Hudi vs Delta vs Iceberg
- How to access localhost:8000 by mobile phone
- Phoenix Architecture 3 - transaction processing
- LeetCode_ Gray code_ Medium_ 89. Gray code
- 腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
- MySQL information schema learning (I) -- general table
- golang的超时处理使用技巧
- Spark foundation -scala
- beegfs高可用模式探讨
猜你喜欢
腾讯架构师首发,2022Android面试笔试总结
手把手教你学会js的原型与原型链,猴子都能看懂的教程
Application of clock wheel in RPC
新一代垃圾回收器—ZGC
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer
LeetCode_双指针_中等_61. 旋转链表
接雨水问题解析
Standardized QCI characteristics
Classic 100 questions of algorithm interview, the latest career planning of Android programmers
In simple terms, interview surprise Edition
随机推荐
logstash高速入口
Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
Spark foundation -scala
Phoenix Architecture 3 - transaction processing
Monthly report of speech synthesis (TTS) and speech recognition (ASR) papers in June 2022
POJ3617 Best Cow Line 馋
[玩转Linux] [Docker] MySQL安装和配置
LeetCode_ Gray code_ Medium_ 89. Gray code
学习探索-使用伪元素清除浮动元素造成的高度坍塌
Example of applying fonts to flutter
PowerPivot——DAX(初识)
(3) Web security | penetration testing | basic knowledge of network security construction, IIS website construction, EXE backdoor generation tool quasar, basic use of
HDU 1026 search pruning problem within the labyrinth of Ignatius and the prince I
学习打卡web
腾讯Android面试必问,10年Android开发经验
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
学习探索-无缝轮播图
Carte de réflexion + code source + notes + projet, saut d'octets + jd + 360 + tri des questions d'entrevue Netease
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
Appx代码签名指南