当前位置:网站首页>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
边栏推荐
- Translation D28 (with AC code POJ 26:the nearest number)
- Interview assault 63: how to remove duplication in MySQL?
- Don't miss this underestimated movie because of controversy!
- 系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
- Dom 操作
- LeetCode-1279. Traffic light intersection
- Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting
- 【pytorch】yolov5 训练自己的数据集
- Unbalance balance (dynamic programming, DP)
- 思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
猜你喜欢

An error occurs when installing MySQL: could not create or access the registry key needed for the

Problems encountered in using RT thread component fish

Blue Bridge Cup microbial proliferation C language

零基础入门PolarDB-X:搭建高可用系统并联动数据大屏

黑馬--Redis篇

利用 clip-path 绘制不规则的图形

Leetcode 30. Concatenate substrings of all words

zabbix 代理服务器 与 zabbix-snmp 监控

DaGAN论文解读
![打家劫舍III[后序遍历与回溯+动态规划]](/img/9b/e9eeed138e46afdeed340bf2629ee1.png)
打家劫舍III[后序遍历与回溯+动态规划]
随机推荐
LeetCode_双指针_中等_61. 旋转链表
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
打家劫舍III[后序遍历与回溯+动态规划]
测试用里hi
After solving 2961 user feedback, I made such a change
[玩转Linux] [Docker] MySQL安装和配置
Mysql Information Schema 學習(一)--通用錶
350. 两个数组的交集 II
MATLAB中deg2rad和rad2deg函数的使用
保证接口数据安全的10种方案
A popular explanation will help you get started
1805. 字符串中不同整数的数目
Learning and Exploration - Seamless rotation map
从sparse.csc.csr_matrix生成邻接矩阵
Tensorflow2.0 self defined training method to solve function coefficients
Chic Lang: attributeerror: partially initialized module 'CV2' has no attribute 'GAPI_ wip_ gst_ GStreamerPipe
黑馬--Redis篇
Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
map的使用(列表的数据赋值到表单,json逗号隔开显示赋值)