• codeforces 560 C. Gerald's Hexagon (思维,几何)


    C. Gerald's Hexagon
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.

    He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.

    Input

    The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6(1 ≤ ai ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.

    Output

    Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.

    Sample test(s)
    input
    1 1 1 1 1 1
    output
    6
    input
    1 2 1 2 1 2
    output
    13
    Note

    This is what Gerald's hexagon looks like in the first sample:

    And that's what it looks like in the second sample:

    题意:给定一个六边形的六条边的长,问能分割成多少个单位正三角形.

    分割不好办,那我们就反着来,先补成一个包含这个六边形的正三角形.

    对于边长为a的正三角形,显然我们可以分割成a*a个单位正三角形

    大正三角形的边长为连续的三条边的和

    而要减掉的三个小三角形的边长为与之前连续的三条边的起始边的序号的奇偶性相同的三条边.

    就是说如果求和的时候求的是前三条边,那么三个要减掉的小三角形的边长就是第一,三,五条边.

    如果求和的时候求的是后三条边,那么三个要减掉的小三角形的边长就是第二,第四,第六条边.

    /*************************************************************************
        > File Name: code/#313/C.cpp
        > Author: 111qqz
        > Email: rkz2013@126.com 
        > Created Time: 2015年08月17日 星期一 07时13分54秒
     ************************************************************************/
    
    #include<iostream>
    #include<iomanip>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<map>
    #include<set>
    #include<queue>
    #include<vector>
    #include<stack>
    #define y0 abc111qqz
    #define y1 hust111qqz
    #define yn hez111qqz
    #define j1 cute111qqz
    #define tm crazy111qqz
    #define lr dying111qqz
    using namespace std;
    #define REP(i, n) for (int i=0;i<int(n);++i)  
    typedef long long LL;
    typedef unsigned long long ULL;
    const int inf = 0x7fffffff;
    int main()
    {
        int a[10];
        int b[5];
        for ( int i = 1 ; i <= 6 ; i++)
        {
        cin>>a[i];
        }
        memset(b,0,sizeof(b));
        for ( int i = 1 ; i <= 6 ; i++)
        {
        if (i<=3)
        {
            b[0] = b[0] + a[i] ;
        }
        if (i%2==1)
        {
            b[i/2+1] = a[i];
        }
        }
        int ans;
        ans = b[0]*b[0]-b[1]*b[1]-b[2]*b[2]-b[3]*b[3];
        cout<<ans<<endl;
      
        return 0;
    }
  • 相关阅读:
    盛最多水的容器
    字符串的排序
    整数拆分
    TCP和UDP编程
    旋转图像
    非递减数列
    不同路径2
    不同路径
    压缩拉伸图片
    Java对List分割及使用Spring多线程调用
  • 原文地址:https://www.cnblogs.com/111qqz/p/4735552.html
Copyright © 2020-2023  润新知