A. Sea Battle

目录

1.Problem

2.Input

3.Output

4.Examples

4.1input

4.2output

5.Code

6.Conclusion


1.Problem

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 w1w1 and a height of h1h1, while the second rectangle has a width of w2w2 and a height of h2h2, where w1≥w2w1≥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)(1,1), the rightmost top cell of the first rectangle has coordinates (w1,h1)(w1,h1), the leftmost bottom cell of the second rectangle has coordinates (1,h1+1)(1,h1+1) and the rightmost top cell of the second rectangle has coordinates (w2,h1+h2)(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.

2.Input

Four lines contain integers w1,h1,w2w1,h1,w2 and h2h2 (1≤w1,h1,w2,h2≤1081≤w1,h1,w2,h2≤108, w1≥w2w1≥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.

3.Output

Print exactly one integer — the number of cells, which should be marked after the ship is destroyed.

4.Examples

4.1input

2 1 2 1

4.2output

12

5.Code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int readInt() {
    int x = 0, f = 1; 
    char ch = getchar();
    while(ch < '0' || ch > '9') {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

int main() {
    ll a1 = readInt(), b1 = readInt(), a2 = readInt(), b2 = readInt();
    
    ll result = a1 + a2 + b1 * 2 + b2 * 2 + abs(a1 - a2) + 4;

    printf("%lld\n", result);
    
    return 0;
}

6.Conclusion

这段C++代码的主要功能是读取四个整数 a1b1a2b2,然后根据一定的数学表达式计算一个结果,并将这个结果输出。

具体而言,代码的执行过程如下:

  1. 使用 readInt 函数读取四个整数 a1b1a2b2,这个函数用于从标准输入读取整数。
  2. 根据给定的表达式计算 result,其中包括 a1 + a2 + b1 * 2 + b2 * 2 + abs(a1 - a2) + 4
  3. 使用 printf 函数输出计算得到的结果 result
  4. 返回0,表示程序正常结束。

总体而言,这段代码实现了简单的数学计算,其结果包括输入整数的加法、乘法、绝对值运算,以及一些常数。最终的计算结果被输出到标准输出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向阳而生__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值