Codeforces Round #517(Div2) A.Golden Plate

A. Golden Plate

time limit per test1 second memory limit per test256 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×h cells.There should be k gilded rings, the first one should go along the edge of the plate, the second one — 2 cells away from the edge and so on. Each ring has a width of 1 cell. Formally, the i-th of these rings should consist of all bordering cells on the inner rectangle of size (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 w, h and k (3≤w,h≤100, 1≤k≤⌊min(n,m)+14⌋, where ⌊x⌋ denotes the number x 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

3 3 1

output

8

input

7 9 1

output

28

input

7 9 2

output

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.

题解

题目大意是给一个 宽X长 的一个矩形,从最外围开始铺 “金砖” ,最外围作为第一层,如果还有第二层,则从宽为 w-4(i-1), 长为 h-4(i-1) (i>1)的矩形的最外层开始铺,问能有多少 “金砖”。
仔细观察便可得到,当只铺第一层时,总的 “金砖” 是 2(w-2) + 2h, 当铺第二层时,第二层铺的“金砖”是在原先的 w 和 h 的基础上减 4 后再应用上述公式,所以很容易就能得到代码。在 w 和 h 大于 0 的条件下应用 k 次上述公式并求和就可得出答案。代码如下:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <utility>
#define ll long long

using namespace std ;

int main(){
    int w , h , k ;
    cin >> w >> h >> k ;
    int ans = 0 ;
    while ( k -- ){
        ans += 2 * (w - 2) + 2 * h ;
        w -= 4 ;
        h -= 4 ;
        if ( w <= 0 || h <= 0 ){
            break ;
        }
    }
    cout << ans << endl ;
    return 0 ;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值