当前位置:网站首页>[蓝桥杯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;
}
边栏推荐
- QT creator shape
- Ansible practical Series III_ Task common commands
- [recommended by bloggers] C WinForm regularly sends email (with source code)
- In the era of DFI dividends, can TGP become a new benchmark for future DFI?
- 解决安装Failed building wheel for pillow
- What does usart1 mean
- Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis
- A trip to Macao - > see the world from a non line city to Macao
- Postman uses scripts to modify the values of environment variables
- Data dictionary in C #
猜你喜欢
![[number theory] divisor](/img/ec/036d7e76cc566c08d336444f2898e1.jpg)
[number theory] divisor
![[free setup] asp Net online course selection system design and Implementation (source code +lunwen)](/img/ac/b518796a92d00615cd374c0c835f38.jpg)
[free setup] asp Net online course selection system design and Implementation (source code +lunwen)

Use dapr to shorten software development cycle and improve production efficiency

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

Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path

QT creator custom build process
![[download app for free]ineukernel OCR image data recognition and acquisition principle and product application](/img/1b/ed39a8b9181660809a081798eb8a24.jpg)
[download app for free]ineukernel OCR image data recognition and acquisition principle and product application

Learning question 1:127.0.0.1 refused our visit

Postman environment variable settings

【博主推荐】SSM框架的后台管理系统(附源码)
随机推荐
[C language foundation] 04 judgment and circulation
图片上色项目 —— Deoldify
Asp access Shaoxing tourism graduation design website
一键提取pdf中的表格
Install mysql5.5 and mysql8.0 under windows at the same time
csdn-Markdown编辑器
QT creator design user interface
MySQL主從複制、讀寫分離
QT creator support platform
Request object and response object analysis
Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
学习问题1:127.0.0.1拒绝了我们的访问
Ansible practical Series II_ Getting started with Playbook
Did you forget to register or load this tag
Database advanced learning notes -- SQL statement
What does BSP mean
[BMZCTF-pwn] 12-csaw-ctf-2016-quals hungman
Invalid global search in idea/pychar, etc. (win10)
虚拟机Ping通主机,主机Ping不通虚拟机