codeforces 560C Gerald's Hexagon (数学+思维)
2017-05-11 20:01
537 查看
题目原文:http://codeforces.com/contest/560/problem/C
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.
题目大意:有一个6个角都是120度的六边形,给你六个边的边长,问可以用多少个边长为1的等边三角形将这个六边形铺满。
解题思路:
尝试过推公式,不过发现比较麻烦。
后来突然想到了面积法,三角形密铺必然最后等于六边形的面积,所以我们只需要求出这个六边形的面积。
现在问题变成了怎么快速求出这个六边形的面积?
最开始尝试用三角划分,不过很容易出现小数,精度没有办法保证,后来突然想到这种六边形是可以从一个大的等边三角形切下三条边得到。大三角形的边长很好求得,三个小三角形的边长也很好求,所以可以得到最后的公式。
ans = (a+b+c)^2 - (a^2 + c^2 + e^2)
AC代码:
/*
@Author: wchhlbt
@Date: 2017/5/11
*/
#include <bits/stdc++.h>
#define Fori(x) for(int i=0;i<x;i++)
#define Forj(x) for(int j=0;j<x;j++)
#define maxn 1111111
#define inf 0x3f3f3f3f
#define ONES(x) __builtin_popcount(x)
using namespace std;
typedef long long ll ;
const double eps =1e-8;
const int mod = 1000000007;
typedef pair<int, int> P;
const double PI = acos(-1.0);
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll n,m,ans;
ll a,b,c,d;
int main()
{
//freopen("input.txt","r",stdin);
int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
int l = (a+b+c);
cout << (l*l) - (a*a + c*c + e*e) << endl;
return 0;
}
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.
题目大意:有一个6个角都是120度的六边形,给你六个边的边长,问可以用多少个边长为1的等边三角形将这个六边形铺满。
解题思路:
尝试过推公式,不过发现比较麻烦。
后来突然想到了面积法,三角形密铺必然最后等于六边形的面积,所以我们只需要求出这个六边形的面积。
现在问题变成了怎么快速求出这个六边形的面积?
最开始尝试用三角划分,不过很容易出现小数,精度没有办法保证,后来突然想到这种六边形是可以从一个大的等边三角形切下三条边得到。大三角形的边长很好求得,三个小三角形的边长也很好求,所以可以得到最后的公式。
ans = (a+b+c)^2 - (a^2 + c^2 + e^2)
AC代码:
/*
@Author: wchhlbt
@Date: 2017/5/11
*/
#include <bits/stdc++.h>
#define Fori(x) for(int i=0;i<x;i++)
#define Forj(x) for(int j=0;j<x;j++)
#define maxn 1111111
#define inf 0x3f3f3f3f
#define ONES(x) __builtin_popcount(x)
using namespace std;
typedef long long ll ;
const double eps =1e-8;
const int mod = 1000000007;
typedef pair<int, int> P;
const double PI = acos(-1.0);
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll n,m,ans;
ll a,b,c,d;
int main()
{
//freopen("input.txt","r",stdin);
int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
int l = (a+b+c);
cout << (l*l) - (a*a + c*c + e*e) << endl;
return 0;
}
相关文章推荐
- CodeForces 560C Gerald's Hexagon【思维】
- 【41.43%】【codeforces 560C】Gerald's Hexagon
- Codeforces 560C Gerald's Hexagon【计算几何】
- CodeForces - 540B School Marks (数学思维题 中位数)
- Codeforces 702D Road to Post Office【捎带数学的思维题】
- Codeforces 758C Unfair Poll 【数学】【思维】
- 【CodeForces 804B】Minimum number of steps(思维+数学)
- Codeforces 357D Xenia and Hamming【数学+思维】
- CodeForces - 899D Shovel Sale 数学+思维
- CodeForces - 611B 数学思维
- 【数学思维】CodeForces - 233B Non-square Equation
- 【组合数学思维】CodeForces - 233C Cycles
- codeforces 560C Gerald's Hexagon(找规律)
- Codeforces 789A Anastasia and pebbles(数学,思维题)
- CodeForces 560C Gerald's Hexagon(几何)
- Codeforces 807C Success Rate【二分+数学思维】
- Codeforces 766E Mahmoud and a xor trip [二进制,]【数学+思维】
- Codeforces 257C:View Angle(思维+数学+atan2函数)
- CodeForces 876B Divisiblity of Differences(思维 + 数学)
- CodeForces 626B Cards(数学思维)