2017 Provincial Blue Bridge Cup B- Grid Division dfs

With the help of big brother code

Problem Description

Cut a 6x6 grid into two parts along the edge of the grid.
The shapes of the two parts are required to be exactly the same.

As shown in the figure: p1.png, p2.png, p3.png are feasible segmentation methods.
Insert picture description here Insert picture description here Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Try to calculate:
Including these three division methods, how many different division methods are there in total?
Note: Rotational symmetry belongs to the same division method.

Please output the whole number, do not fill in any extra content or explanatory text.
enter

No input
output

An integer
hint

Use printf or cout to output the answer

Ideas

Typical DFS search path questions.
If you cut the sample pattern, you will find that there are only two points on the boundary, and they must pass through the (3,3) point. Then take (3,3) as the starting point for a deep search.
If you find a point deeply, then its central symmetry point is equivalent to the search. If the boundary is found, then its central symmetry point is also to the boundary along the already searched Cut the past points, then the
cut two graphics are center-symmetric graphics, but pay attention to the final result to be divided by 4.
For example: we start from the point (3,3) all the way to the right to the boundary, or all the way to the left, Or all the way up, or all the way down, the graphics are the same

Code:

#include <stdio.h>
int dx[4]={
    
    1,0,-1,0},dy[4]={
    
    0,1,0,-1}; //四个方向变化坐标 !!用这种方法写更简便 (一维数组) 
int cnt=0;
int map[7][7]={
    
    0};//初始化
void DFS(int x,int y)
{
    
    
	if(x==0||x==6||y==0||y==6)
	{
    
    
		cnt++;
		return;
	}		
	for(int i=0;i<4;i++)//四个方向
	{
    
    
		int newx=x+dx[i];
		int newy=y+dy[i];
		if(map[newx][newy]==0)
		{
    
    
			map[newx][newy]=1;
			map[6-newx][6-newy]=1;
			DFS(newx,newy);
			map[newx][newy]=0; //用过之后赋回初值 
			map[6-newx][6-newy]=0;
		}	
	}
}
int main()
{
    
    
	map[3][3]=1;//从中心开始,3,3表示中心的点
	DFS(3,3);
	printf("%d",cnt/4);//因为旋转对称是一种 上下左右 四个剪法 
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_47874905/article/details/109043706