CF 559A(Gerald's Hexagon-几何割补法)

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.

Sample test(s)
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:



我的做法是算出面积求


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
double a[7],x[7],y[7];
double theta=3.1415926/3;
void rotate(double &x,double &y)
{
	double x2=cos(theta)*x+sin(theta)*y;
	double y2=-sin(theta)*x+cos(theta)*y;
	x=x2;y=y2;	 
}
int n=6;
int main()
{
//	freopen("A.in","r",stdin);
//	freopen(".out","w",stdout);
	while(1)
	{
		For(i,n) cin>>a[i];
		
		x[0]=y[0]=0;
		double dx=1,dy=0;
		For(i,n)
		{
			x[i]=x[i-1]+dx*a[i];
			y[i]=y[i-1]+dy*a[i];
			rotate(dx,dy);
		}
		
		double S=0,S1=sqrt(3)/4.0;
		Rep(i,n)
		{
			S+=x[i]*y[i+1]-x[i+1]*y[i];
		}
		cout<<(int)(-S/S1/2)<<endl;
		
//		For(i,n)
//			printf("%lf %lf\n",x[i],y[i]);
		break;
	}
 
	
	return 0;
}

然而std是...








posted @ 2017-04-23 13:40  jzdwajue  阅读(153)  评论(0编辑  收藏  举报