【Live Archive】6393 Self-Assembly【强连通】

2024-09-05 14:18

本文主要是介绍【Live Archive】6393 Self-Assembly【强连通】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

传送门:【Live Archive】6393 Self-Assembly

题目分析:

假设我们只用到向上或者向右的块,这样我们只要找到一个回路使得某个块可以和第一个块一样,那么我们就相当于找到了一个循环,这样就可以无限循环了。

但是我们要怎样去找这么一个环?考虑到必须是对应字母 X+,X 才能建边,然后一个环中一定是多个一对一对的这样的对应字母组成的。

可以发现块的数量那么大也是无所谓的,因为我们用到的有用的信息只是块中的四个变量。考虑到一个块中有 A+,B,C,D+ ,那么我们可以建立有向边 A+B+,BA 。表示有 A+ 的块可以和有 B+ 的块相连,有 B 的块可以和有 A 的块相连。其他边同理。

然后我们只要找到一个环就可以说明存在无限循环了。

PS:其实找环这一个过程用不到求强连通的= =,只不过我脑残了写了一个强连通,拓扑什么的其实更简单,只是我太懒了不想重写了。

my  code:

#include <stdio.h>
#include <string.h>
#include <set>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std ;typedef long long LL ;#define clr( a , x ) memset ( a , x , sizeof a )
#define cpy( a , x ) memcpy ( a , x , sizeof a )const int MAXN = 100 ;
const int MAXE = 1000005 ;struct Edge {int v , n ;Edge () {}Edge ( int v , int n ) : v ( v ) , n ( n ) {}
} ;Edge E[MAXE] ;
int H[MAXN] , cntE ;
int S[MAXN] , top ;
char s[MAXN] ;
int scc[MAXN] , scc_cnt ;
int vis[MAXN][MAXN] ;
int ok ;
int dfn[MAXN] , low[MAXN] , dfs_clock ;
int n ;void init () {cntE = 0 ;dfs_clock = 0 ;scc_cnt = 0 ;clr ( scc , 0 ) ;clr ( dfn , 0 ) ;clr ( H , -1 ) ;
}void addedge ( int u , int v ) {E[cntE] = Edge ( v , H[u] ) ;H[u] = cntE ++ ;
}void tarjan ( int u ) {dfn[u] = low[u] = ++ dfs_clock ;S[top ++] = u ;for ( int i = H[u] ; ~i ; i = E[i].n ) {int v = E[i].v ;if ( !dfn[v] ) {tarjan ( v ) ;low[u] = min ( low[u] , low[v] ) ;} else if ( !scc[v] ) {low[u] = min ( low[u] , dfn[v] ) ;}}if ( dfn[u] == low[u] ) {++ scc_cnt ;int x = 0 ;do {scc[S[-- top]] = scc_cnt ;++ x ;} while ( S[top] != u ) ;if ( x > 1 ) ok = 1 ;}
}void solve () {init () ;ok = 0 ;for ( int i = 1 ; i <= n ; ++ i ) {scanf ( "%s" , s ) ;top = 0 ;for ( int j = 0 ; j < 8 ; j += 2 ) {char a = s[j] ;char b = s[j + 1] ;if ( a == '0' ) continue ;int x = a - 'A' ;if ( b == '-' ) S[top ++] = x << 1 ;else S[top ++] = x << 1 | 1 ;}for ( int j = 0 ; j < top ; ++ j ) {for ( int k = j + 1 ; k < top ; ++ k ) {int x = S[j] ;int y = S[k] ;if ( x == ( y ^ 1 ) ) ok = 1 ;addedge ( x , y ^ 1 ) ;addedge ( y , x ^ 1 ) ;}}}top = 0 ;for ( int i = 1 ; i < 52 ; ++ i ) {if ( !dfn[i] ) tarjan ( i ) ;if ( ok ) break ;}if ( ok ) printf ( "unbounded\n" ) ;else printf ( "bounded\n" ) ;
}int main () {while ( ~scanf ( "%d" , &n ) ) solve () ;return 0 ;
}

这篇关于【Live Archive】6393 Self-Assembly【强连通】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1139199

相关文章

【VueJS】live-server 快速搭建服务 及 注意事项

本地开发常常需要搭建临时的服务,第一时间我们会想到用 http-server。 但现在流行修改文件浏览器自动刷新,这里可以使用 live-server 很简单就能启动一个看起来很专业的本地服务。 你只需要全局安装live-server: npm install -g live-server 并在项目根目录执行这条命令: PS E:\AblazeProject\Vue> live-serv

Docker容器创建时,无法访问镜像源:Could not connect to archive.ubuntu.com:80

1.问题描述 当基于dockerfile创建容器时,遇到Could not connect to ...、Failed to fetch ...等异常时,大概原因是没有配置好容器创建所需的镜像源。这里以Ubuntu基础镜像源为例。 dockerfile内容 FROM ubuntuRUN apt update && apt install python3 -y && apt install

像素间的关系(邻接、连通、区域、边界、距离定义)

文章目录 像素的相邻像素4邻域D邻域8邻域 邻接、连通、区域和边界邻接类型连通区域边界 距离测度欧氏距离城市街区距离(city-block distance)棋盘距离(chessboard distance) 参考 像素的相邻像素 4邻域 坐标 ( x , y ) (x,y) (x,y)处的像素 p p p有2个水平的相邻像素和2个垂直的相邻像素,它们的坐标是: ( x

jQuery Mobile 的.bind()、.live()和.delegate()之间区别

资料一: live方法是bind方法的变种,其基本功能就同bind方法的功能是一样的,都是为一个元素绑定某个事件,但是bind方法只能给当前存在的元素绑定事件,对于事后采用JS等方式新生成的元素无效,而live方法则正好弥补了bind方法的这个缺陷,它可以对后生成的元素也可以绑定相应的事件。      live方法之所以能对后生成的元素也绑定相应的事件的原因归结在“事件委托”上面,所谓

OpenCV结构分析与形状描述符(6)带统计的连通组件计算函数connectedComponentsWithStats()的使用

操作系统:ubuntu22.04 OpenCV版本:OpenCV4.9 IDE:Visual Studio Code 编程语言:C++11 算法描述 connectedComponentsWithStats 函数计算布尔图像的连通组件标记图像,并为每个标记产生统计信息。 该函数接受一个具有4或8连通性的二值图像,并返回 N,即标签总数(标签范围为 [0, N-1],其中 0 代表背景标签)

最小连通网络

使用网络中的n-1条边来连接网络中的n个顶点 不产生回路 各边上的权值总和达到最小 prim算法:针对顶点展开,适合边的数量较多的情况 kruskal算法:针对边展开的,适合边的数量较少的情况

[LeetCode] 238. Product of Array Except Self

题:https://leetcode.com/problems/product-of-array-except-self/description/ 题目 Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all

【HDU】2242 考研路茫茫——空调教室 双连通分量+树型DP

考研路茫茫——空调教室 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1978    Accepted Submission(s): 576 Problem Description 众所周知,HDU的考研教室是没

【HDU】3861 The King’s Problem 强连通缩点+有向图最小路径覆盖

传送门:【HDU】3861 The King’s Problem 题目分析:首先强连通缩点,因为形成一个环的王国肯定在一条路径中,这样才能保证拆的少。 然后缩点后就是DAG图了,由于题目要求的是最小路径覆盖,那么二分匹配即可。 代码如下: #include <cstdio>#include <cstring>#include <algorithm>#includ

【Live Archive】6395 SurelyYouCongest【最短路+最大流】

传送门:【Live Archive】6395 SurelyYouCongest 题目分析:我们只要从点1开始做一次最短路预处理,然后对于给定的源点们,对于最短路图构成一个层次图,然后由于每一层都是互不影响的,所以我们对每一层暴力跑网络流就好了。 my  code: my~~code: #include <stdio.h>#include <string.h>#include <set>