zoukankan      html  css  js  c++  java
  • Codeforces Round #133 (Div. 2) A. Tiling with Hexagons(数学)

    A. Tiling with Hexagons
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.

    The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has abcab and c adjacent tiles, correspondingly.

    To better visualize the situation, look at the picture showing a similar hexagon for a = 2b = 3 and c = 4.

    According to the legend, as the King of Berland obtained the values ab and c, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?

    Input

    The first line contains three integers: ab and c (2 ≤ a, b, c ≤ 1000).

    Output

    Print a single number — the total number of tiles on the hall floor.

    Sample test(s)
    input
    2 3 4
    
    output
    18

    采用“补形”的方法,将六边形补全为平行四边形,如题中所示的例子,延长边a和c使之相交,要延长多少?答案是a-1。即将原六边形补全为一个(c + a - 1)× (b + a -1)的平行四边形,只要再减去多出的部分即可。

    于是n = (b + a - 1) * (c + a - 1) - 2 * ((a - 1) + 1) * (a - 1) / 2  = (b + a - 1) * (c + a - 1) - a * (a - 1);

    AC CODE:

    #include <iostream>
    using namespace std;
    
    int main()
    {
        int a, b, c, n;
        while(cin >> a >> b >> c)
        {
            n = (b + a - 1) * (c + a - 1) - a * (a - 1);
            cout << n << endl;
        }
        return 0;
    }
    


  • 相关阅读:
    PHP与WCF第一次亲密接触
    PHP操作MongoDB
    如何用SVN进行个人版本管理
    【Android】还原“微信”apk中的“发现”和“我”两个模块
    使php支持mbstring库
    mysql 与 mysqli的区别
    nginx 配置正向 HTTP 代理服务器[转]
    正向代理与反向代理的区别【Nginx读书笔记】
    为什么要使用Nginx?
    【转】关于HTTP中文翻译的讨论
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910489.html
Copyright © 2011-2022 走看看