Editorial for Cutting Cake

Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Tommoa

Editorialist: Tommoa

Cutting cake is a question that was first used in the third PCS standard contest.

This problem focuses on requiring good geometric knowledge, specifically of circles and chords within those circles. The only formula that is of any relevance from the linked page is \(h = R - \sqrt{R^2 + \dfrac{c^2}{4}}\), and the area of the cake \(A = (R-h)^2*pi\). We can simplify this to \(A = (R^2 + \dfrac{c^2}{4})^2\). Simply read the input and output \(A\).

#include <bits/stdc++.h>
using namespace std;

long T;
long double R, C;

int main() {
    cin >> T;
    while (T--) {
        cin >> R >> C;
        cout << setprecision(7) << fixed << (R*R - (((double)(C*C))/4))*M_PI << endl;


  • 0
    Ccamm  commented on March 13, 2019, 2:15 p.m.

    Any advice on making this answer even shorter?

    for test in [list(map(int, l.split())) for l in stdin.read().split('\n')[1:-1]]: print(math.pi*(math.pow(test[0],2)-1/4*math.pow(test[1],2)))