CF1131A.Sea Battle
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w1 and a height of h1, while the second rectangle has a width of w2 and a height of h2, where w1≥w2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field.
The rectangles are placed on field in the following way:
- the second rectangle is on top the first rectangle;
- they are aligned to the left, i.e. their left sides are on the same line;
- the rectangles are adjacent to each other without a gap.
See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue.
Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1,1), the rightmost top cell of the first rectangle has coordinates (w1,h1), the leftmost bottom cell of the second rectangle has coordinates (1,h1+1) and the rightmost top cell of the second rectangle has coordinates (w2,h1+h2).
After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green.
Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction.
为了使“海战”游戏更加有趣,鲍里斯决定为其添加一种新型舰船。该舰船由两个矩形组成:第一个矩形宽为 w1、高为 h1,第二个矩形宽为 w2、高为 h2,其中 w1≥w2。本游戏中仅使用一艘这样的舰船(即由这两个矩形构成),且战场上不存在其他舰船。
这两个矩形按如下方式放置在战场上:
- 第二个矩形位于第一个矩形的正上方;
- 二者左对齐,即它们的左侧边位于同一条竖直线上;
- 二者彼此紧邻,中间无空隙。
参见注释中的图片:第一个矩形为红色,第二个矩形为蓝色。
形式化地,我们引入一个坐标系。此时,第一个矩形最左下方的格子坐标为 (1,1),其最右上方的格子坐标为 (w1,h1);第二个矩形最左下方的格子坐标为 (1,h1+1),其最右上方的格子坐标为 (w2,h1+h2)。
当该舰船被完全击毁后,所有与舰船共享一条边或一个顶点(即八连通邻接)的格子均会被标记。当然,仅标记那些不属于舰船本身的格子。注释中的图片中,此类格子以绿色标出。
请计算:舰船被完全击毁后,总共需要标记多少个格子?游戏战场在任意方向上均为无限大。
输入格式
Four lines contain integers w1,h1,w2 and h2 (1≤w1,h1,w2,h2≤108, w1≥w2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles.
四行,每行包含一个整数:w1、h1、w2 和 h2(1≤w1,h1,w2,h2≤108,且 w1≥w2)—— 分别表示第一个矩形的宽度、第一个矩形的高度、第二个矩形的宽度以及第二个矩形的高度。不允许旋转矩形。
输出格式
Print exactly one integer — the number of cells, which should be marked after the ship is destroyed.
恰好输出一个整数——即在舰船被摧毁后需要标记的格子数量。
输入输出样例
输入#1
2 1 2 1
输出#1
12
输入#2
2 2 1 2
输出#2
16
说明/提示
In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares):

In the second example the field looks as:

在第一个例子中,棋盘如下所示(第一个矩形为红色,第二个矩形为蓝色,绿色表示被标记的方格):

在第二个例子中,棋盘如下所示:

输入解题思路,AI测评打分。不知道怎么写?