当前位置:网站首页>[蓝桥杯2017初赛]方格分割
[蓝桥杯2017初赛]方格分割
2022-07-06 09:14:00 【%xiao Q】
题目

分析
因为每种方案都是经过中间那个点(3,3),所以我们可以从(3,3)开始分2个方向 搜索(并且这2方向是对称的,所以当一个方向到边界,另一个也会到边界,也就是一种答案)
参考代码
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;
typedef pair<int, int> PII;
bool st[10][10] = {
0};
int dx[] = {
1, -1, 0, 0};
int dy[] = {
0, 0, 1, -1};
int ans = 0;
void dfs(int x, int y)
{
// 遇到边界就是一种方案
if(x == 0 || x == 6 || y == 0 || y == 6)
{
ans++;
return ;
}
rep(i, 0, 3)
{
int x1 = x + dx[i], y1 = y + dy[i];
int x2 = 6 - x1, y2 = 6 - y1; //(X1,y1)关于(3,3)对称的点
if(x1 < 0 || x1 > 6 || y1 < 0 || y1 > 6 || st[x1][y1]) continue;
st[x1][y1] = st[x2][y2] = true; //2个对称的点同是标记
dfs(x1, y1);
st[x1][y1] = st[x2][y2] = false; //回溯
}
}
int main()
{
st[3][3] = true;
dfs(3, 3);
cout << ans / 4 << endl; // 因为上下,左右都是对称的,所以除与4
return 0;
}
边栏推荐
- Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'
- Base de données Advanced Learning Notes - - SQL statements
- Punctual atom stm32f103zet6 download serial port pin
- 数据库高级学习笔记--SQL语句
- QT creator custom build process
- SSM integrated notes easy to understand version
- Software testing - interview question sharing
- Windows下安装MongDB教程、Redis教程
- 虚拟机Ping通主机,主机Ping不通虚拟机
- Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
猜你喜欢

Why can't I use the @test annotation after introducing JUnit

Introduction and use of automatic machine learning framework (flaml, H2O)

A brief introduction to the microservice technology stack, the introduction and use of Eureka and ribbon

【博主推荐】C# Winform定时发送邮箱(附源码)

Basic use of redis
![[C language foundation] 04 judgment and circulation](/img/59/4100971f15a1a9bf3527cbe181d868.jpg)
[C language foundation] 04 judgment and circulation

Rhcsa certification exam exercise (configured on the first host)

一键提取pdf中的表格

error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead

Use dapr to shorten software development cycle and improve production efficiency
随机推荐
The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
基于apache-jena的知识问答
一键提取pdf中的表格
Installation and use of MySQL under MySQL 19 Linux
数据库高级学习笔记--SQL语句
02 staff information management after the actual project
QT creator uses Valgrind code analysis tool
机器学习笔记-Week02-卷积神经网络
01 project demand analysis (ordering system)
Julia 1.6 1.7 common problem solving
Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
Base de données Advanced Learning Notes - - SQL statements
Rhcsa certification exam exercise (configured on the first host)
QT creator support platform
Test objects involved in safety test
Antlr4 uses keywords as identifiers
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
[Thesis Writing] how to write function description of jsp online examination system
MySQL完全卸载(Windows、Mac、Linux)
[number theory] divisor