当前位置:网站首页>Blue Bridge Cup Sprint - binary enumeration
Blue Bridge Cup Sprint - binary enumeration
2022-04-22 05:58:00 【Tchaikovsky】
Blue Bridge Cup Sprint —— Binary enumeration
What is binary enumeration ?
link : Binary enumeration .
Seven segment code
link : Seven segment code .

This question is a little circuitous , The code has been modified for a while
There are a little more judgment conditions here .
The whole idea is :
- Enumerate all the situations
- For each case, judge whether it is connected by searching the set
Enumeration, I use binary enumeration here , The advantage is that it is relatively fast , But here is a question to fill in the blank , There are only 120 What kind of situation , use DFS It's OK, too
Judgment of connectivity is mainly divided into and and Judge Two aspects
- and : As long as the two lights are connected, they merge .
I think too much here , Because we are Before and after , Without repeating judgment , Don't think about breaking or because it has two ends , Head inconsistency .
- Judge : After we've sorted out the search collection , as long as pre[t] Or myself (t) The situation is a connected section ( You can draw pictures to understand ). in other words , The number of segments is greater than 1, It's not connected
Complete code
import java.util.Scanner;
public class test {
public static int count=0;
public static boolean[][] l = new boolean[8][8];
public static void init() {
l[1][1] = l[1][2]=l[1][6] = true;
l[2][2] = l[2][1]=l[2][7] = l[2][3]=true;
l[3][3] = l[3][2]=l[3][4] = l[3][7]=true;
l[4][4] = l[4][3]=l[4][5] = true;
l[5][5] = l[5][4]=l[5][7] = l[5][6]=true;
l[6][6] = l[6][1]=l[6][7] = l[6][5]=true;
l[7][7] = l[7][2]=l[7][3] = l[7][5]=l[7][6]=true;
}
public static void main(String[] args) {
init();
for(int i=0;i<(1<<7);i++) {
int[] light = new int[8];
for(int j=0;j<7;j++) {
if((i&(1<<j))>0) {
light[j+1]=1;
}
}
System.out.println();
if(check(light)) {
count++;
}
}
System.out.println(count);
}
public static boolean check(int[] lights) {
int i=1,j=1;
int[] pre= {
0,1,2,3,4,5,6,7};
while(i<8) {
if(lights[i]==1) {
for(j=i+1;j<8;j++) {
if(lights[j]==1) {
if(l[i][j]) {
join(i,j,pre);
}
}
}
}
i++;
}
int count=0;
for(int t=1;t<8;t++) {
if(lights[t]==1&&pre[t]==t)
count++;
}
return count==1;
}
public static int find(int x,int[] pre) {
if(pre[x] == x) return x;
return pre[x] = find(pre[x],pre);
}
public static void join(int x,int y,int[] pre) {
int px = find(x,pre),py = find(y,pre);
if(px!=py)
pre[px] = py;
}
}
版权声明
本文为[Tchaikovsky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220537235545.html
边栏推荐
猜你喜欢

2021 408 changes in postgraduate entrance examination outline

机器学习入门——Numpy中的比较与Fancy Indexing

ubuntu20.0.4下在终端安装数据库

torch nn. Parameter trainable parameter definition

Alist easy to use guide

LeetCode 2049. Count the number of nodes with the highest score -- traversal of the tree

Blue Bridge Cup 31 day sprint Day17

12 - 容器-字符串

正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 有一些软件包无法被安装。如果您用的是 unstable 发行版,这也许是 因为系统

13 - container - List
随机推荐
ubuntu20.0.4下在终端安装数据库
Apple CMS custom docking WeChat official account
最长公共子序列(动态规划)
LeetCode 514. The road of freedom -- dynamic programming
蓝桥杯31天冲刺 Day10
Introduction to machine learning -- comparison and fancy indexing in numpy
10 - 流程控制-while循环语句
golang学习和校招经历
06 - data type
TCGA database Ensembl ID is transformed into gene symbol to extract the required RNA species expression profile list information
LeetCode 1591. Strange printer II -- judgment sorting
Meilisearch usage record
棋盘覆盖问题(分治)
torch nn. Parameter trainable parameter definition
B/S架构
Explanation of "write a byte to the output stream. The bytes to be written are the eight low bits of parameter B. the 24 high bits of B will be ignored"
蓝桥杯31天冲刺 Day17
Summary of SQL interview questions (under update)
卷积神经网络
16 - Container Comprehensive Training