-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpizza2.cpp
46 lines (36 loc) · 1.04 KB
/
pizza2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @file pizza2.cpp
* @author William Weston
* @brief Kattis Pizza Crust Problem
* @version 0.1
* @date 2023-06-15
*
* @copyright Copyright (c) 2023
*
* Source: https://open.kattis.com/problems/pizza2
*/
#include <cstdlib>
#include <iomanip>
#include <iostream>
auto percent_cheese( int pizza_radius, int cm_of_crust ) -> long double;
auto
main() -> int
{
int R, C;
while ( std::cin >> R >> C )
{
std::cout << std::fixed << std::setprecision( 9 ) << std::showpoint
<< percent_cheese( R, C )
<< '\n';
}
return EXIT_SUCCESS;
}
auto
percent_cheese( int pizza_radius, int cm_of_crust ) -> long double
{
static constexpr long double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
auto const cheese_radius = pizza_radius - cm_of_crust;
auto const pizza_area = pi * pizza_radius * pizza_radius;
auto const cheese_area = pi * cheese_radius * cheese_radius;
return ( cheese_area / pizza_area ) * 100.0;
}