程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 第六周O題(等邊三角形個數),第六周等邊

第六周O題(等邊三角形個數),第六周等邊

編輯:C++入門知識

第六周O題(等邊三角形個數),第六周等邊


O - 計數 Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u  

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畫等邊三角形,統計六邊形內部三角形的個數,統計時采用容斥原理即可。

盜圖一張。。 

 這裡輸入的邊長為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;
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved