A. Golden Plate

本文介绍了一种算法,用于计算在一个矩形盘子上,按照特定规则镀金的单元格总数。盘子被划分为w×h个单元格,需要镀k层金环,每层金环距离边缘递增2个单元格,宽度为1个单元格。文章提供了输入输出样例及代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into w×hw×h cells. There should be kk gilded rings, the first one should go along the edge of the plate, the second one — 22 cells away from the edge and so on. Each ring has a width of 11 cell. Formally, the ii-th of these rings should consist of all bordering cells on the inner rectangle of size (w−4(i−1))×(h−4(i−1))(w−4(i−1))×(h−4(i−1)).

The picture corresponds to the third example.
Your task is to compute the number of cells to be gilded.

Input
The only line contains three integers ww, hh and kk (3≤w,h≤1003≤w,h≤100, 1≤k≤⌊min(n,m)+14⌋1≤k≤⌊min(n,m)+14⌋, where ⌊x⌋⌊x⌋ denotes the number xx rounded down) — the number of rows, columns and the number of rings, respectively.

Output
Print a single positive integer — the number of cells to be gilded.

Examples
inputCopy
3 3 1
outputCopy
8
inputCopy
7 9 1
outputCopy
28
inputCopy
7 9 2
outputCopy
40
Note
The first example is shown on the picture below.
The second example is shown on the picture below.
The third example is shown in the problem description.

#include<iostream>
using namespace std;

int main()
{
    int w, h, k;
    while(cin >> w >> h >> k)
    {
        int sum = 0;
        for(int i = 0; i < k; ++i)
        {
            sum += 2 * (w + h) - 4;
            w -= 4;
            h -= 4;
        }
        cout << sum << '\n';
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值