当前位置:网站首页>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
边栏推荐
- LeetCode_ Double pointer_ Medium_ 61. rotating linked list
- How to access localhost:8000 by mobile phone
- [translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
- 从sparse.csc.csr_matrix生成邻接矩阵
- Classic 100 questions of algorithm interview, the latest career planning of Android programmers
- Analysis of rainwater connection
- 【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
- String长度限制?
- LeetCode_格雷编码_中等_89.格雷编码
- 腾讯云数据库公有云市场稳居TOP 2!
猜你喜欢
MySQL information schema learning (I) -- general table
激进技术派 vs 项目保守派的微服务架构之争
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech
Mysql Information Schema 学习(二)--Innodb表
In simple terms, interview surprise Edition
Low CPU load and high loadavg processing method
Using clip path to draw irregular graphics
腾讯安卓开发面试,android开发的基础知识
Li Kou 101: symmetric binary tree
随机推荐
Phoenix Architecture 3 - transaction processing
PHP与EXCEL PHPExcel
企业精益管理体系介绍
语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech
Test Li hi
Logstash expressway entrance
PowerPivot——DAX(初识)
【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
腾讯架构师首发,2022Android面试笔试总结
Unbalance balance (dynamic programming, DP)
技术分享 | 抓包分析 TCP 协议
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
DaGAN论文解读
About image reading and processing, etc
腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
Cesium 点击绘制圆形(动态绘制圆形)
Dom 操作
A5000 vGPU显示模式切换
Swiftui game source code Encyclopedia of Snake game based on geometryreader and preference