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
Input1 1 1 1 1 1Output
6Input
1 2 1 2 1 2Output
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畫等邊三角形,統計六邊形內部三角形的個數,統計時采用容斥原理即可。
盜圖一張。。
這裡輸入的邊長為3 4 2 6 1 5 ,通過填補的到一個正三角形,正三角形的邊長len就是前三個邊a1+a2+a3=9,這個正三角形中含有邊長為1的三角形的個數就是len*len=81,然後減去三個角的三角形個數即可,這三個三角形也是正三角形,所以減去的三角形個數就是3*3+2*2+1*1,所以六邊形含有的邊長為1的三角形個數為81-(3*3+2*2+1*1)=67
代碼:
#include<iostream> using namespace std; int main() { int a1,a2,a3,a4,a5,a6; cin>>a1>>a2>>a3>>a4>>a5>>a6; int len=a1+a2+a3; cout<<len*len-a1*a1-a3*a3-a5*a5<<endl; }