#abc250a. A - Adjacent Squares
A - Adjacent Squares
Score : points
问题描述
存在一个包含 行(水平方向)和 列(垂直方向)的网格。令 表示从上到下的第 行、从左到右的第 列的方格。
找出与方格 共享边的方格数量。
这里,两个方格 和 被认为共享一条边当且仅当 (其中 表示 的绝对值)。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with horizontal rows and vertical columns. Let denote the square at the -th row from the top and the -th column from the left.
Find the number of squares that share a side with Square .
Here, two squares and are said to share a side if and only if (where denotes the absolute value of ).
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
3 4
2 2
Sample Output 1
4
We will describe Sample Inputs/Outputs , and at once below Sample Output .
Sample Input 2
3 4
1 3
Sample Output 2
3
Sample Input 3
3 4
3 4
Sample Output 3
2
When and , the grid looks as follows.
- For Sample Input , there are squares adjacent to Square .
- For Sample Input , there are squares adjacent to Square .
- For Sample Input , there are squares adjacent to Square .
Sample Input 4
1 10
1 5
Sample Output 4
2
Sample Input 5
8 1
8 1
Sample Output 5
1
Sample Input 6
1 1
1 1
Sample Output 6
0
update @ 2024/3/10 10:40:28