当前位置:网站首页>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
边栏推荐
- 企业精益管理体系介绍
- A method of removing text blur based on pixel repair
- PMP practice once a day | don't get lost in the exam -7.6
- 【基础架构】Flink/Flink-CDC的部署和配置(MySQL / ES)
- JDBC details
- Hudi vs Delta vs Iceberg
- IC设计流程中需要使用到的文件
- Interpretation of Dagan paper
- [translation] Digital insider. Selection process of kubecon + cloudnativecon in Europe in 2022
- MySQL information schema learning (I) -- general table
猜你喜欢
spark基础-scala
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
C language daily practice - day 22: Zero foundation learning dynamic planning
[calculating emotion and thought] floor sweeper, typist, information panic and Oppenheimer
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
利用 clip-path 绘制不规则的图形
时钟轮在 RPC 中的应用
[translation] linkerd's adoption rate in Europe and North America exceeded istio, with an increase of 118% in 2021.
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
随机推荐
Phoenix Architecture 2 - accessing remote services
谷粒商城--分布式高级篇P129~P339(完结)
Recursive implementation of department tree
学习打卡web
Use of deg2rad and rad2deg functions in MATLAB
Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
In depth analysis, Android interview real problem analysis is popular all over the network
Test Li hi
[玩转Linux] [Docker] MySQL安装和配置
冒烟测试怎么做
Simple application of VBA script in Excel
算法面试经典100题,Android程序员最新职业规划
Dom 操作
[translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
LeetCode_ Gray code_ Medium_ 89. Gray code
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
An error occurs when installing MySQL: could not create or access the registry key needed for the
CPU负载很低,loadavg很高处理方法