Codeforces Round #313 (Div. 1)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mystery_guest/article/details/69924055


A. 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.

Examples
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:


题意:六边形,能分成多少个三角形。该六边形每个角都是120度

代码很简单,两行搞定,但是不太好想。


我们考虑将这个六边形延伸,成一个等边三角形(必然为等边三角形,因为该六边形每个角为120度)


当边长为3时,三角形为9

然而一个等边三角形内三角形的个数可以由等差数列得出,结果为l^2。(l为三角形边长),到这里,我们就可以得出答案了,从补全的等边三角形,减去三个角上能分成的三角形个数,就是答案。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#define eps 1e-8
#define zero(x) (((x>0?(x):-(x))-eps)
#define mem(a,b) memset(a,b,sizeof(a))
#define memmax(a) memset(a,0x3f,sizeof(a))
#define pfn printf("\n")
#define ll __int64
#define ull unsigned long long
#define sf(a) scanf("%d",&a)
#define sf64(a) scanf("%I64d",&a)
#define sf264(a,b) scanf("%I64d%I64d",&a,&b)
#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define sf464(a,b,c,d) scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)
#define sf564(a,b,c,d,ee) scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&ee)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sf5(a,b,c,d,ee) scanf("%d%d%d%d%d",&a,&b,&c,&d,&ee)
#define sff(a) scanf("%f",&a)
#define sfs(a) scanf("%s",a)
#define sfs2(a,b) scanf("%s%s",a,b)
#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)
#define sfd(a) scanf("%lf",&a)
#define sfd2(a,b) scanf("%lf%lf",&a,&b)
#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)
#define sfc(a) scanf("%c",&a)
#define ull unsigned long long
#define pp pair<int,int>
#define debug printf("***\n")
#define pi 3.1415927
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
bool cmpbig(int a, int b){ return a>b; }
bool cmpsmall(int a, int b){ return a<b; }
using namespace std;
int main()
{
   // freopen("data.in","r",stdin);
    //freopen("data.out" ,"w",stdout);
    int a[6];
    while(~sf(a[0]))
    {
        rep(i,1,6)
            sf(a[i]);
        int l=a[0]+a[1]+a[2];
        cout<<l*l-a[0]*a[0]-a[2]*a[2]-a[4]*a[4]<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/mystery_guest/article/details/69924055