当前位置:网站首页>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
边栏推荐
- The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
- 激进技术派 vs 项目保守派的微服务架构之争
- [translation] micro survey of cloud native observation ability. Prometheus leads the trend, but there are still obstacles to understanding the health of the system
- 社招面试心得,2022最新Android高频精选面试题分享
- 【翻译】Linkerd在欧洲和北美的采用率超过了Istio,2021年增长118%。
- GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions
- 利用 clip-path 绘制不规则的图形
- [玩转Linux] [Docker] MySQL安装和配置
- A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
- 深入分析,Android面试真题解析火爆全网
猜你喜欢
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
PMP practice once a day | don't get lost in the exam -7.6
JDBC details
Reflection and illegalaccessexception exception during application
黑馬--Redis篇
Black Horse - - Redis Chapter
Mysql Information Schema 学习(一)--通用表
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
IC设计流程中需要使用到的文件
Detailed idea and code implementation of infix expression to suffix expression
随机推荐
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
Dom 操作
Unbalance balance (dynamic programming, DP)
[玩转Linux] [Docker] MySQL安装和配置
Swagger2 reports an error illegal DefaultValue null for parameter type integer
通俗的讲解,带你入门协程
从sparse.csc.csr_matrix生成邻接矩阵
Alibaba data source Druid visual monitoring configuration
zabbix 代理服务器 与 zabbix-snmp 监控
深入浅出,面试突击版
PMP practice once a day | don't get lost in the exam -7.6
Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting
[translation] supply chain security project in toto moved to CNCF incubator
MySQL information schema learning (II) -- InnoDB table
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
Translation D28 (with AC code POJ 26:the nearest number)
Using clip path to draw irregular graphics
CF960G - Bandit Blues(第一类斯特林数+OGF)
Mysql Information Schema 学习(二)--Innodb表
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe