A. Golden Plate

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;
}
全部评论

相关推荐

点赞 评论 收藏
分享
废物一个0offer:认真的吗二本本科找人工智能岗位
点赞 评论 收藏
分享
牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务