codeforces-559A-Gerald's Hexagon
2015-10-31 11:58
555 查看
codeforces-559A-Gerald’s Hexagon
[code] time limit per test2 seconds memory limit per test256 megabytes
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.
input
1 1 1 1 1 1
output
6
input
1 2 1 2 1 2
output
13
题目链接:cf-559A
题目大意:给出一个六边形(所有角度都是120度)的六条边长,问,里面由几个边长问1的正三角形组成。
题目思路:每个角都是120度的六边形显然可以补成正三角形,然后用正三角形的面积减去补出来的三个正三角形。
S = 1/2absinC 所以三角形个数是S(大三角形)/S(每个小三角形) 即,个数 = S边长的平方。
以下是代码:
[code]#include <vector> #include <map> #include <set> #include <algorithm> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <string> #include <cstring> using namespace std; int main(){ int a,b,c,d,e,f; cin >> a >> b >> c >> d >> e >> f; int ans = (a + b + c) * (a + b + c) - (a * a + c * c + e * e); cout << ans << endl; return 0; }
相关文章推荐
- golang 数组长度与定义长度(容量)
- django
- Beego框架使用
- Django返回EXcel
- Designing Efficient Algorithms [Examples]~C - Calculator Conundrum
- Designing Efficient Algorithms [Examples]~F - City Game
- Django RestFramework源码剖析(2)———Viwe是自带分页的
- Django RestFramework源码剖析(1)——设定不同的serializer
- Golang time包的定时器/断续器
- KM算法模板(HDU_2255)
- [Simple Algorithms] Lesson1 简化版的桶排序
- 编写你的第一个Django应用01
- 二分图带权匹配的KM算法以及费用流建模
- CDOJ 1221 Ancient Go
- erlang和go之间桥接库相关
- [Django后台管理系统]Django的标准库django.contrib包介绍
- Golang的select/非缓冲的Channel实例详解
- [Django后台管理系统]激活Django自带的管理界面
- sicily 1306. Sorting Algorithm
- D - Wine trading in Gergovia