A Golden Plate

版权声明:大家一起学习,欢迎转载,转载请注明出处。若有问题,欢迎纠正! https://blog.csdn.net/memory_qianxiao/article/details/83268695

A. Golden Plate

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 11cell. 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

input

Copy

3 3 1

output

Copy

8

input

Copy

7 9 1

output

Copy

28

input

Copy

7 9 2

output

Copy

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.

题意:输入一个矩形的宽(w)和高(h)和这个矩形里面有k个嵌套矩形。输出有多少个小方块。具体要结合样例中和图形理解题意。

题解:数论  计算方法就是依次计从最大的矩形计算形当前的块数,然后矩形宽和高依次递减4,这样循环k次。每次块数是(w+h)*2-4(4个顶角多算了一次),然后w-=4,h-=4。规律可以尝试几个就会发现。

c++:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int w,h,k,ans=0;
    cin>>w>>h>>k;
    while(k--)
    {
        ans+=(w+h)*2-4;
        w-=4,h-=4;
    }
    cout<<ans<<endl;
    return 0;
}

python:

w,h,k=map(int,input().split())
ans=0
for i in range(k):
    ans+=(w+h)*2-4
    w-=4;h-=4;
print(ans)

猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/83268695