102500: [AtCoder]ABC250 A - Adjacent Squares
Description
Score : $100$ points
Problem Statement
There is a grid with $H$ horizontal rows and $W$ vertical columns. Let $(i,j)$ denote the square at the $i$-th row from the top and the $j$-th column from the left.
Find the number of squares that share a side with Square $(R, C)$.
Here, two squares $(a,b)$ and $(c,d)$ are said to share a side if and only if $|a-c|+|b-d|=1$ (where $|x|$ denotes the absolute value of $x$).
Constraints
- All values in input are integers.
- $1 \le R \le H \le 10$
- $1 \le C \le W \le 10$
Input
Input is given from Standard Input in the following format:
$H$ $W$ $R$ $C$
Output
Print the answer as an integer.
Sample Input 1
3 4 2 2
Sample Output 1
4
We will describe Sample Inputs/Outputs $1,2$, and $3$ at once below Sample Output $3$.
Sample Input 2
3 4 1 3
Sample Output 2
3
Sample Input 3
3 4 3 4
Sample Output 3
2
When $H=3$ and $W=4$, the grid looks as follows.
- For Sample Input $1$, there are $4$ squares adjacent to Square $(2,2)$.
- For Sample Input $2$, there are $3$ squares adjacent to Square $(1,3)$.
- For Sample Input $3$, there are $2$ squares adjacent to Square $(3,4)$.
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
Input
题意翻译
有一个 $h$ 行 $w$ 列的网格,给出其中一个网格的坐标 $(x,y)$ (表示该网格在第 $x$ 行第 $y$ 列),问在网格图中有多少与该网格有边相邻的正方形。Output
分数:$100$ 分
问题描述
有一个网格,包含 $H$ 行水平行和 $W$ 列垂直列。记 $(i,j)$ 表示从顶部数第 $i$ 行,从左数第 $j$ 列的正方形。
找出与 Square $(R, C)$ 共享边的正方形的数量。
这里,两个正方形 $(a,b)$ 和 $(c,d)$ 只有当 $|a-c|+|b-d|=1$ 时(其中 $|x|$ 表示 $x$ 的绝对值)才被称为共享边。
约束条件
- 输入中的所有值都是整数。
- $1 \le R \le H \le 10$
- $1 \le C \le W \le 10$
输入
输入通过标准输入给出以下格式:
$H$ $W$ $R$ $C$
输出
打印一个整数作为答案。
样例输入 1
3 4 2 2
样例输出 1
4
我们将在样例输出 3 之后一次性描述样例输入/输出 1、2 和 3。
样例输入 2
3 4 1 3
样例输出 2
3
样例输入 3
3 4 3 4
样例输出 3
2
当 $H=3$ 和 $W=4$ 时,网格如下所示。
- 对于样例输入 1,与 Square $(2,2)$ 相邻的正方形有 4 个。
- 对于样例输入 2,与 Square $(1,3)$ 相邻的正方形有 3 个。
- 对于样例输入 3,与 Square $(3,4)$ 相邻的正方形有 2 个。
样例输入 4
1 10 1 5
样例输出 4
2
样例输入 5
8 1 8 1
样例输出 5
1
样例输入 6
1 1 1 1
样例输出 6
0