zoukankan      html  css  js  c++  java
  • Codeforces Round #313 (Div. 1) A.Gerald's Hexagon

    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:

    题解:奇妙的做法。。。窝萌可以把它补成一个正三角形,然后减去三个小正三角形。。。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<queue>
     6 #include<cstring>
     7 #define PAU putchar(' ')
     8 #define ENT putchar('
    ')
     9 using namespace std;
    10 int A[6];
    11 inline int read(){
    12     int x=0,sig=1;char ch=getchar();
    13     for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=0;
    14     for(;isdigit(ch);ch=getchar())x=10*x+ch-'0';
    15     return sig?x:-x;
    16 }
    17 inline void write(int x){
    18     if(x==0){putchar('0');return;}if(x<0)putchar('-'),x=-x;
    19     int len=0,buf[15];while(x)buf[len++]=x%10,x/=10;
    20     for(int i=len-1;i>=0;i--)putchar(buf[i]+'0');return;
    21 }
    22 void init(){
    23     for(int i=0;i<6;i++)A[i]=read();
    24     int L=A[0]+A[1]+A[2];int S=L*L;
    25     S-=A[0]*A[0]+A[2]*A[2]+A[4]*A[4];
    26     write(S);
    27     return;
    28 }
    29 void work(){
    30     return;
    31 }
    32 void print(){
    33     return;
    34 }
    35 int main(){init();work();print();return 0;}
  • 相关阅读:
    《程序员修炼之道》阅读笔记2
    《程序员修炼之道》阅读笔记1
    Ubuntu16桥接模式上网并设置静态ip
    读《架构漫谈》有感
    质量属性6个常见属性的场景分析
    sql注水
    python版本切换
    使用vue-cli构建 webpack打包工具时,生产环境下,每次build时,删除dist目录,并重新生成,以防dist目录文件越来越多。
    Java栈与堆
    从一个字符串s的第i个字符(不包括此字符)开始删除n个字符
  • 原文地址:https://www.cnblogs.com/chxer/p/4673114.html
Copyright © 2011-2022 走看看