Codeforces 560C Gerald's Hexagon(几何)

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

Sample test(s)
input
1 1 1 1 1 1
output
6
input
1 2 1 2 1 2
output
13

题意:

输入一个六边形的六条边,(保证这个六边形的每个内角是120度)

在六边形内部画一些线

求构成的等边三角形的个数


思路:

先分析内角均是120度的六边形的特征

先看两种特殊情况

左边那个是6条边全部相等
右边那个是a2 = a6 && a3 = a5

一般情况:


a5-(a2-a6)=a3    ===》   a2+a3 = a5+a6

所以只要满足a2+a3=a5+a6就可以开始一层一层的加了

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	int a[6];
	for(int i=1;i<=6;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=3;i++)//将起始边固定
	{
		if(a[2]+a[3]==a[5]+a[6])//满足这个条件,起始边肯定一样了
		{
			break;
		}
		int f=a[1];
		for(int j=1;j<6;j++)
		{
			a[j] = a[j+1];
		}
		a[6]=f;
	}
	__int64 s1=a[1]+a[1]+1,s2=a[4]+a[4]+1;
	__int64 ans=s1+s2;
	for(int i=2;i<=min(a[2],a[6]);i++)//从a[1]开始,一层一层的加上去
	{
		s1 += 2;
		ans+=s1;
	}
	ans+=(s1+1)*abs(a[2]-a[6]);//中间的平行四边形
	for(int i=2;i<=min(a[5],a[3]);i++)//从a[4]开始往上加
	{
		s2+=2;
		ans+=s2;
	}
	printf("%I64d\n",ans);
	return 0;
}



猜你喜欢

转载自blog.csdn.net/kaisa158/article/details/47019343
今日推荐