Codeforces Round #133 (Div. 2) A. Tiling with Hexagons(数学)
2012-08-17 15:31
471 查看
A. Tiling with Hexagons
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.
The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has a, b, c, a, b and c adjacent
tiles, correspondingly.
To better visualize the situation, look at the picture showing a similar hexagon for a = 2, b = 3 and c = 4.
![](http://codeforces.ru/renderer/1298c4ab167f24cf56b1dc9bd301622c18b6803b.png)
According to the legend, as the King of Berland obtained the values a, b and c,
he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?
Input
The first line contains three integers: a, b and c (2 ≤ a, b, c ≤ 1000).
Output
Print a single number — the total number of tiles on the hall floor.
Sample test(s)
input
output
采用“补形”的方法,将六边形补全为平行四边形,如题中所示的例子,延长边a和c使之相交,要延长多少?答案是a-1。即将原六边形补全为一个(c + a - 1)× (b + a -1)的平行四边形,只要再减去多出的部分即可。
于是n = (b + a - 1) * (c + a - 1) - 2 * ((a - 1) + 1) * (a - 1) / 2 = (b + a - 1) * (c + a - 1) - a * (a - 1);
AC CODE:
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.
The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has a, b, c, a, b and c adjacent
tiles, correspondingly.
To better visualize the situation, look at the picture showing a similar hexagon for a = 2, b = 3 and c = 4.
![](http://codeforces.ru/renderer/1298c4ab167f24cf56b1dc9bd301622c18b6803b.png)
According to the legend, as the King of Berland obtained the values a, b and c,
he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?
Input
The first line contains three integers: a, b and c (2 ≤ a, b, c ≤ 1000).
Output
Print a single number — the total number of tiles on the hall floor.
Sample test(s)
input
2 3 4
output
18
采用“补形”的方法,将六边形补全为平行四边形,如题中所示的例子,延长边a和c使之相交,要延长多少?答案是a-1。即将原六边形补全为一个(c + a - 1)× (b + a -1)的平行四边形,只要再减去多出的部分即可。
于是n = (b + a - 1) * (c + a - 1) - 2 * ((a - 1) + 1) * (a - 1) / 2 = (b + a - 1) * (c + a - 1) - a * (a - 1);
AC CODE:
#include <iostream> using namespace std; int main() { int a, b, c, n; while(cin >> a >> b >> c) { n = (b + a - 1) * (c + a - 1) - a * (a - 1); cout << n << endl; } return 0; }
相关文章推荐
- Codeforces Round #133 (Div. 2) A. Tiling with Hexagons(数学)
- Codeforces Round #392 (Div. 2) A(水)B(水、模拟) C(数学) D(贪心)
- Codeforces Round #354 (Div. 2) E. The Last Fight Between Human and AI 数学
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C. Lengthening Sticks(数学)
- Codeforces Round #318 (Div. 2) D Bear and Blocks (数学)
- Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C 数学
- Codeforces Round #191 (Div. 2) C. Magic Five(数学,逆元取膜模板)
- Codeforces Round #204 (Div. 2) C. Jeff and Rounding——数学规律
- Codeforces Round #157 (Div. 1) C. Little Elephant and LCM (数学、dp)
- CF#309-DIV2-C. Kyoya and Colored Balls-组合数学
- Codeforces Round #324 (Div. 2) 584B. Kolya and Tanya 组合数学
- Codeforces Round #364 (Div. 2) D As Fast As Possible(数学)
- Codeforces Round #379 (Div. 2) F Anton and School(数学)
- Codeforces Round #445 Div1 C:Maximum Element (组合数学+DP)
- Codeforces Round #280 (Div. 2) E. Vanya and Field 数学
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举
- Codeforces Round #308 (Div. 2) C. Vanya and Scales (数学常识,进制转换)
- Codeforces Round #282 (Div. 2) B.(数学)