img
Czech ACM Student Chapter
Czech Technical University in Prague
Charles University in Prague
Technical University of Ostrava
acm
ˇ a
Slovak University of Technology
Pavol Jozef Saf´rik University in Koˇice
s
cz
ˇ
University of Zilina
Masaryk University
Matej Bel University in Bansk´ Bystrica
a
University of West Bohemia
CTU Open Contest 2019
Beer Coasters
coasters.c, coasters.cpp, Coasters.java, coasters.py
Often, in an average pub, the beer is served in a mug which is, quite obviously, wet from inside,
but also wet from outside. The barkeeper typically has no capacity to dry freshly washed
mugs. To protect the table and the (optional!) tablecloth, beer coasters are used in most
pubs. Originally, the beer coasters were round, nowadays you can find a variety of different
shapes. Despite being perceived as slightly unorthodox, square and even rectangular coasters
are manufactured and used daily in many self-respecting restaurants, taverns, beer houses and
drinkeries of high and low profiles.
A research related to the well-known satiric Ig Nobel Prize is being conducted in local pubs.
The research aims to measure the rate of wear of the rectangular coasters. The rate of wear
depends also on how much a coaster is getting wet from the contact with the wet bottom of beer
mugs. That, in turn, depends on the exact area of contact between the mug and the coaster.
The exact position of the coaster and the mug on the table is recorded each time the mug is put
on the coaster.
Many sophisticated calculations in the research take as input the area of contact, which has to
be calculated by a suitable computer program. You are to write such a program.
Input Specification
The input contains 7 space-separated integers on a single line. The first three integers X , Y , R
describe the coordinates of the beer mug bottom on the table. The center of the mug bottom is
at (X , Y ) and the radius of the mug bottom is R. The next four integers Ax, Ay , Bx, By describe
the coordinates of two opposite corners, (Ax, Ay ) and (Bx, By ), of the coaster on the table. The
coaster is a rectangle placed with its sides parallel to the coordinate axes. All coordinates are
in the range from -1 000 to 1 000, the radius is in the range from 1 to 1 000. The radius and
the coordinates are expressed in the same units of length.
Output Specification
Output a single decimal number with precision of 4 digits after the decimal point, the area of
contact between the coaster and the beer mug.
Sample Input 1
Output for Sample Input 1
-1 0 2 -1 -2 3 2
6.2832