当前位置:网站首页>A horse stopped a pawn
A horse stopped a pawn
2022-06-21 14:47:00 【User 6978604】
Title source :C Language network 1266
Problem description
On the chessboard A There is a river crossing pawn , Need to get to the goal B spot . The rules of pawn walking : You can go down 、 Or to the right . At the same time on the chessboard C There's a horse on the other side , The point where the horse is located and all the points that can be reached in one step of jumping are called the control points of the opposing horse . So it's called “ A pawn crossing the river ”. The chessboard is represented by coordinates ,A spot (0, 0)、B spot (n, m)(n, m For no more than 15 The integer of ), The same coordinates of the horse's position need to be given . Now I ask you to calculate the number of soldiers from A Point can reach B The number of paths of points , Suppose the horse's position is fixed , It's not a step by step .
Input
Four data in a row , respectively B Point coordinates and horse coordinates .( Make sure all the data is clear )
Output
A data , Indicates the number of paths .
The sample input
6 6 3 5Sample output
6problem solving
/*
* @Author: YaleXin
* @Date: 2020-05-24 13:34:01
* @LastEditTime: 2020-05-24 14:16:01
* @LastEditors: YaleXin
* @Description:
* @FilePath: \my_c_workspace\dotcpp\1266.c
* @ Prayer does not appear BUG
*/
#include <stdio.h>
/**
* @x : Abscissa of the horse @y : Ordinate of horse
*/
int path[16][16] = {0}, sum = 0, n, m, x, y;
/**
* Initialize the exclusion zone
*/
void setHorse() {
path[x][y] = 1;
if ((x - 2) >= 0 && (y - 1) >= 0) path[x - 2][y - 1] = 1;
if ((x - 1) >= 0 && (y - 2) >= 0) path[x - 1][y - 2] = 1;
if ((x - 2) >= 0 && (y + 1) <= m) path[x - 2][y + 1] = 1;
if ((x - 1) >= 0 && (y + 2) <= m) path[x - 1][y + 2] = 1;
if ((x + 2) <= n && (y - 1) >= 0) path[x + 2][y - 1] = 1;
if ((x + 1) <= n && (y - 2) >= 0) path[x + 1][y - 2] = 1;
if ((x + 2) <= n && (y + 1) <= m) path[x + 2][y + 1] = 1;
if ((x + 1) <= n && (y + 2) <= m) path[x + 1][y + 2] = 1;
}
void findPath(int nowX, int nowY) {
if (nowX == n && nowY == m) {
sum++;
return;
}
// First to the right
if ((nowY + 1) <= m && !path[nowX][nowY + 1]) findPath(nowX, nowY + 1);
// following
if ((nowX + 1) <= n && !path[nowX + 1][nowY]) findPath(nowX + 1, nowY);
}
int main() {
scanf("%d%d%d%d", &n, &m, &x, &y);
setHorse();
// First to the right
if (!path[0][1]) findPath(0, 1);
// following
if (!path[1][0]) findPath(1, 0);
printf("%d", sum);
return 0;
}边栏推荐
- Kubeneters' CNI network plug-in installation Kube ovn
- Summary of statistical learning methods
- [how to install MySQL 8.0 to a non system disk] [how to create a new connection with Navicat and save it to a non system disk] and [uninstall MySQL 8.0]
- 我的Debug之路1.0
- Chart. JS 2.0 doughnut tooltip percentage - chart js 2.0 doughnut tooltip percentages
- T32 add toolbar button
- Chapter 4 - network layer
- Nodejs setting domestic source
- Reasonably set the number of threads 【 rpm 】
- Qt-6-file IO
猜你喜欢

Explain the design idea and capacity expansion mechanism of ThreadLocal in detail

JS written test question: array

Qt-4-common classes and components

Nmap scan port tool

Qt-8- use SQL database

Two of my essays

P24 de noise
![The whole process of Netease cloud music API installation and deployment [details of local running projects and remote deployment]](/img/3b/678fdf93cf6cc39caaec8e753af169.jpg)
The whole process of Netease cloud music API installation and deployment [details of local running projects and remote deployment]

What are the log files in MySQL?

Promotion guide for large enterprises: material preparation, PPT writing and on-site defense
随机推荐
Selection (041) - what is the output of the following code?
Redis5.0 installation and production startup steps
Win10 installation and configuration mongodb
Format printout
Summary of the most basic methods of numpy
Complete and detailed installation steps for kubeneter version 1.7
HSV color model and color component range in opencv
Three questions for learning new things
There is a PPP protocol between routers. How can there be an ARP broadcast protocol
2022 Fujian latest fire protection facility operator simulation test question bank and answers
[untitled] fish pond forwarding command
我的Debug之路1.0
Interview - difference between pointer and reference
The code remotely calls aria2 to download URL resources or BT seeds
Judge password strength - Optimization
Clickhouse cluster installation has too many dry goods
JS interview questions: variable promotion function promotion, scope chain error prone questions
启牛学堂app下载证券开户,是安全的吗?有风险嘛?
Dplayer development barrage background
Selection (042) - what is the output of the following code?