当前位置:网站首页>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
边栏推荐
- 【云小课】EI第47课 MRS离线数据分析-通过Flink作业处理OBS数据
- After solving 2961 user feedback, I made such a change
- 腾讯T3大牛手把手教你,大厂内部资料
- 在解决了 2961 个用户反馈后,我做出了这样的改变...
- OceanBase社区版之OBD方式部署方式单机安装
- Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
- Transformer model (pytorch code explanation)
- 【计算情与思】扫地僧、打字员、信息恐慌与奥本海默
- Zero foundation entry polardb-x: build a highly available system and link the big data screen
- 350. Intersection of two arrays II
猜你喜欢
学习打卡web
Analysis of rainwater connection
Blue Bridge Cup microbial proliferation C language
Standardized QCI characteristics
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
beegfs高可用模式探讨
信息系统项目管理师---第八章 项目质量管理
PowerPivot——DAX(初识)
【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
腾讯T4架构师,android面试基础
随机推荐
Standardized QCI characteristics
POJ3617 Best Cow Line 馋
Yyds dry goods inventory leetcode question set 751 - 760
转让malloc()该功能后,发生了什么事内核?附malloc()和free()实现源
Vscode debug run fluent message: there is no extension for debugging yaml. Should we find yaml extensions in the market?
小微企业难做账?智能代账小工具快用起来
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer
腾讯T3大牛手把手教你,大厂内部资料
AsyncHandler
接雨水问题解析
思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
腾讯T2大牛亲自讲解,跳槽薪资翻倍
Example of shutter text component
DOM operation
Interpretation of Dagan paper
121. 买卖股票的最佳时机
Unbalance balance (dynamic programming, DP)
[translation] supply chain security project in toto moved to CNCF incubator
Analysis of rainwater connection