ACM 计数

Description

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 Input

Input
1 1 1 1 1 1
Output
6
Input
1 2 1 2 1 2
Output
13

Hint

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

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

解题思路:

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

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

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

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

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

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

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

程序代码:

 

#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int a1,a2,a3,a4,a5,a6;
    scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5,&a6);
    int x=(a4+a5+a6)*(a4+a5+a6)-a2*a2-a4*a4-a6*a6;
    printf("%d\n",x);
    return 0;
}

 

  自己没想出来,借鉴别人的代码

 

posted @ 2015-08-19 15:51  心向晴  阅读(334)  评论(0编辑  收藏  举报