ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1084. Goat in the Garden

easy solution in c++
Posted by Yucheng 2 Mar 2019 14:50
#include<iostream>
#include<cmath>
#include<iomanip>
#define pi 3.1415926
using namespace std;

int main(){
    float side,len;
    cin>>side>>len;
    if(len>(side/2)*sqrt(2)){
        cout<<fixed<<setprecision(3)<<side*side;
        return 0;
    }
    if((side/2)>=len){
        cout<<fixed<<setprecision(3)<<len*len*pi;
        return 0;
    }
    float cosx=(side/2)/len;
    float sinx=sqrt(1-cosx*cosx);
    float cosA=2*sinx*cosx;
    float theta=acos(cosA);
    cout<<fixed<<setprecision(3)<<len*len*0.5*theta*4+sqrt(len*len-(side/2)*(side/2))*(side/2)*4;

return 0;
}