codeforces 560C Gerald's Hexagon (数学+思维)
来源:互联网 发布:下拉框淘宝店铺 编辑:程序博客网 时间:2024/06/05 10:06
题目原文: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.
The first and the single line of the input contains 6 space-separated integersa1, 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.
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 (数学+思维)
- CodeForces 560C Gerald's Hexagon【思维】
- Codeforces 560C Gerald's Hexagon(几何)
- codeforces 560 C Gerald's Hexagon
- CodeForces 560C Gerald's Hexagon
- CodeForces 560C Gerald's Hexagon
- CodeForces - 560C Gerald's Hexagon
- CodeForces 560C Gerald's Hexagon
- 【41.43%】【codeforces 560C】Gerald's Hexagon
- codeforces 560C Gerald's Hexagon(找规律)
- Codeforces 560C Gerald's Hexagon【计算几何】
- Codeforces Round #313 C. Gerald's Hexagon(放三角形)
- CodeForces#313 C. Gerald's Hexagon
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 几何
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
- Codeforces Round #313 (Div. 2) C Gerald's Hexagon 计数
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
- Codeforces Round #313 (Div. 2)--C. Gerald's Hexagon
- Windows下直接使用gettimeofday函数
- LPC2478 定时器2和定时器3的启用
- 从Hive表中进行数据抽样-Sampling
- 【响应式Web设计】读书笔记
- CEF3 二进制文件及资源文件说明
- codeforces 560C Gerald's Hexagon (数学+思维)
- 在linux上安装jdk和tomcat(二):配置网络
- freemarker.core.NonMethodException: [... Exception message was already printed; see it above ...]
- 2017/6/6日-本科毕设那些事
- 字符和数字转换问题
- 类
- ss-libev 源码解析local篇(1): ss_local的启动,客户端连入
- git将代码提交到github
- Android系统从