当前位置:网站首页>Blue Bridge Cup seven segment code (dfs/ shape pressing + parallel search)

Blue Bridge Cup seven segment code (dfs/ shape pressing + parallel search)

2022-06-24 07:33:00 Lin Shiliu should work hard

#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
using namespace std;
int g[10][10]; 
//abcdefg
//0123456
int p[10];
bool vis[10];
int res;
void init()
{
	for(int i=0;i<10;i++) p[i]=i;
	memset(vis,false,sizeof vis);
}
int find(int x)
{
	if(p[x]!=x) p[x]=find(p[x]);
	return p[x];
}
void solve()
{
	for(int i=1;i<1<<7;i++)
	{
		init();
		int st=i;
		for(int j=0;j<7;j++)
			if(st>>j&1)
				vis[j]=true;
		for(int j=0;j<7;j++)
			for(int k=0;k<7;k++)
				if(vis[j]&&vis[k]&&g[j][k]==1)
				{
					int a=find(j),b=find(k);
					if(a!=b) p[a]=b;
				}
		int t=0;
		for(int j=0;j<7;j++)
			if(p[j]==j&&vis[j]) t++;
		if(t==1) res++;
	}
}
int main()
{
	g[0][1]=g[0][5]=1;
	g[1][0]=g[1][6]=g[1][2]=1;
	g[2][1]=g[2][6]=g[2][3]=1;
	g[3][2]=g[3][4]=1;
	g[4][5]=g[4][6]=g[4][3]=1;
	g[5][0]=g[5][4]=g[5][6]=1;
	g[6][1]=g[6][2]=g[6][4]=g[6][5]=1;
	solve();
	cout<<res;
} 

 

原网站

版权声明
本文为[Lin Shiliu should work hard]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211619323603.html