Thứ Tư, 15 tháng 8, 2012

Problem Tiling with Hexagons


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 abcab and c adjacent tiles, correspondingly.
To better visualize the situation, look at the picture showing a similar hexagon for a = 2b = 3 and c = 4.
According to the legend, as the King of Berland obtained the values ab 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: ab 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
Solution:
DevC:

#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin >> a >> b >> c;
cout << (b*c)+(a-1)*(b+c-1);
return 0;
}
free pascal:


var
    a,b,c:longint;
begin
    read(a,b,c);
    write(b*c+(a-1)*(b+c-1));
    readln;
    readln;
end.

















Không có nhận xét nào:

Đăng nhận xét