Source Code
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 7;
int n;

// the good template
#define cd complex<double>
#define cld complex<ld>
#define ci complex<int>
#define cll complex<long long>
#define ld long double
#define ll long long

const double pi = acos(-1.0), eps = 1e-9;

template <class T>
istream &operator>>(istream &is, complex<T> &p)
{
       T val;
       is >> val, p.real(val);
       is >> val, p.imag(val);
       return is;
}
template <class T>
ostream &operator<<(ostream &os, complex<T> p) { return os << " " << real(p) << " " << imag(p) << " \n"; }

template <class T>
double dot(T x, T y) { return real(conj(x) * y); }

template <class T>
double cross(T x, T y) { return imag(conj(x) * y); }

template <class T>
T trans(T x, T y) { return x + y; }

template <class T>
T scale(T x, T y, double rat) { return x + (y - x) * rat; }

template <class T>
T rot(T x, double ang) { return x * polar(1.0, ang); }

template <class T>
T perp(T x) { return T(-imag(x), real(x)); }

template <class T>
double ang(T x, T y) { return acos(dot(x, y) / abs(x) / abs(y)); }

template <class T>
bool half(T x) { return imag(x) > 0 || (imag(x) == 0 && real(x) < 0); }

template <class T>
vector<T> circirIntersection(T x, double r1, T y, double r2)
{
       vector<T> ret;
       double d = abs(y - x);
       double xo1 = (r1 * r1 + d * d - r2 * r2) / (2 * r1 * d);
       double theta = acos(xo1);
       if (r1 + r2 >= d)
       {
              T vec = (y - x) / d * r1;
              ret = {x + rot(vec, theta), x + rot(vec, -theta)};
       }
       if (ret[0] == ret[1])
              ret.pop_back();
       return ret;
}

template <class T>
vector<T> pointCircleTangent(T c, double r, T p)
{
       vector<T> ret;
       double dist = norm(p - c);
       if (dist > r * r)
       {
              T ur = (p - c) * r / sqrt(dist);
              double theta = acos(r / sqrt(dist));
              ret.pb(c + rot(ur, theta));
              ret.pb(c + rot(ur, -theta));
       }
       return ret;
}

template <class T>
double arcDist(double r, T p1, T p2)
{
       double d = abs(p1 - p2);
       double theta = acos((2.0 * r * r - d * d) / (2.0 * r * r));
       return r * theta;
}

inline double AAS(double a1, double a2, double side) { return side * side / 2.0 / (1.0 / tan(a1) + 1.0 / tan(a2)); }
inline double SSA(double s1, double s2, double a1) { return 0.5 * s1 * s2 * sin(a1); }
inline double SSS(double s1, double s2, double s3)
{
       double ss = (s1 + s2 + s3) / 2.0;
       return sqrt(ss * (ss - s1) * (ss - s2) * (ss - s3));
}
template <class T>
pair<T, bool> lineintersection(T a, T b, T c, T d)
{
       ld A = imag(b) - imag(a), B = real(a) - real(b), C = -A * real(a) - B * imag(a);
       ld A0 = imag(d) - imag(c), B0 = real(c) - real(d), C0 = -A0 * real(c) - B0 * imag(c);
       ld de = cross(cd(A, B), cd(A0, B0));
       ld xm = cross(cd(C, B), cd(C0, B0));
       ld ym = cross(cd(A, C), cd(A0, C0));
       if (fabs(de) == 0)
              return {cd(0, 0), 0};
       return {cd(-xm / de, -ym / de), 1};
}

template <class T>
inline bool onRay(T x, T y, T z) { return cross(y - z, z - x) == 0 && dot(y - x, z - x) >= 0; }

template <class T>
inline bool belong(T x, T y, T z) { return onRay(x, y, z) && onRay(y, x, z); }

template <class T>
pair<T, bool> SegmentIntersection(T a, T b, T c, T d, bool construct = 0)
{
       pair<T, bool> ret = {cd(0, 0), 0};

       if (cross(b - a, d - c) == 0)
       {
              if (cross(b - a, c - a))
                     return ret;
              for (int i = 0; i < 2; ++i)
              {
                     if (belong(a, b, c))
                            ret = {c, 1};
                     else if (belong(a, b, d))
                            ret = {d, 1};
                     swap(a, c), swap(b, d);
              }
              return ret;
       }
       else
       {
              for (int i = 0; i < 2; ++i)
              {
                     ll sign1 = cross(b - a, c - a);
                     ll sign2 = cross(b - a, d - a);
                     if ((sign1 > 0 && sign2 > 0) || (sign1 < 0 && sign2 < 0))
                            return ret;
                     swap(a, c), swap(b, d);
              }
       }
       ret.s = 1;
       if (construct)
              ret = lineintersection(a, b, c, d);
       return ret;
}

inline ll jcross(cll x, cll y) { return 1ll * real(x) * imag(y) - 1ll * real(y) * imag(x); }

template <class T>
ll polygonArea(vector<T> &vec)
{
       ll ret = 0;
       for (int i = 1; i + 1 < sz(vec); ++i)
              ret += jcross(vec[i + 1] - vec[0], vec[i] - vec[0]);
       return abs(ret);
}
template <class T>
int PointInPolygon(vector<T> &vec, T z)
{
       T rs = T(real(z) + 1, 1e9 + 1);
       int cnt = 0;
       int siz = (int)vec.size();
       for (int i = 0; i < siz; ++i)
       {
              T p1 = vec[i], p2 = vec[(i + 1) % z];
              if (belong(p1, p2, z))
                     return 0;
              if (SegmentIntersection(z, rs, vec[i], vec[(i + 1) % z]).s)
                     ++cnt;
       }
       return cnt & 1 ? 1 : -1;
}

template <class T>
vector<T> ConvexHull(vector<T> poly)
{
       vector<T> ret;
       sort(all(poly), [&](T x, T y)
            { return real(x) < real(y) || (real(x) == real(y) && imag(x) < imag(y)); });
       for (int i = 0; i < 2; ++i)
       {
              const int S = sz(ret);
              for (auto u : poly)
              {
                     while (sz(ret) >= S + 2 && cross(ret.end()[-1] - ret.end()[-2], u - ret.end()[-1]) >= 0)
                            ret.pop_back();
                     ret.pb(u);
              }
              ret.pop_back();
              reverse(all(poly));
       }
       return ret;
}

template <class T>
bool pointInsideConvexPolygon(vector<T> &vec, T p)
{
       if (vec.empty())
              return false;
       int z = sz(vec);
       for (int i = 0; i < z; ++i)
       {
              T x = vec[i], y = vec[(i + 1) % z];
              if (cross(y - x, p - y) < 0)
                     return 0;
       }
       return 1;
}

// >> the end of the good template

int  l, k;

const double EPS = 1e-12 ; 
double L ; 
long double solve(long double mid)
{
       long double area = pi * mid * mid;
       long double area2 = area;

       long double side = 0;

       cd A(0, 0);
       long double th = 2.0 * pi / n ; 
       cd B = cd( real(A) + l * cos(th) , imag(A) + l * sin(th) );

       for(int j = 0 ;j < n ; ++ j){
              cd y = cd( L * cos(th * j) , L * sin(th*j)) ; 
              if(j == 0) A = y ; 
              else if(j == 1) B = y ; 
              // cout << y ; 
       }
       if( norm(A) - EPS<= mid * mid && norm(B) - EPS<= mid * mid ){
              long double ar = .25 * l * l * n / tan( pi / n) ; 
              // cout<< ar <<"+" << area << endl;  
              // cout<< ar ; exit(0) ; 
              return ar  ; 
       } 
       long double a = imag(B) - imag(A) ; 
       long double b = real(A) - real(B) ; 
       long double c = -a * real(A) - b * imag(A) ; 
       long double r = mid; 
       long double x0 = -a * c / (a * a + b * b), y0 = -b * c / (a * a + b * b);
       if (c * c > r * r * (a * a + b * b) + EPS){
              // assert(0) ; 
              return area;  
       }
       else if (abs(c * c - r * r * (a * a + b * b)) < EPS)
       {
              // assert(0) ; 
              return area ; 
       }
       else
       {
              // assert(0) ; 
              // cout<<"*";
              long double d = r * r - c * c / (a * a + b * b);
              long double mult = sqrt(d / (a * a + b * b));
              long double ax, ay, bx, by;
              ax = x0 + b * mult;
              bx = x0 - b * mult;
              ay = y0 - a * mult;
              by = y0 + a * mult;
              long double theta = ang( cd(ax, ay) , cd(bx, by) ) ;
              // cout << endl; 
              // cout << ax <<" " << ay <<" " << endl  << bx <<" " << by << endl; 
              // cout << endl ;  
              long double ar = theta / (2 * pi) * area - 0.5 * abs(dot( cd(ax,ay) , cd(bx,by) )); 
              area2 -= 1.0 * n * ar ; 
              // cout << area <<" " << area2 << '_' << endl ;

              // cout <<ar << " " << .25 * l * l * n / tan(pi / n) <<"***\n";
              // cout << norm( cd(ax,ay) - cd(bx , by) ) << endl;
              // cout << ax << " " << ay <<" " << bx <<" " << by << endl; 
       for(int j = 0 ;j < n ; ++ j){
              cd y = cd( mid * cos(th * j) , mid * sin(th*j)) ; 
              if(j == 0) A = y ; 
              else B = y ; 
              // cout << y ; 
       }              
       // exit(0) ; 
              // puts("2 points");
              // cout << ax << ' ' << ay << '\n'
              //      << bx << ' ' << by << '\n';
       }
       return 1.0 * area2 ;
}

double getl(double x){
       double lo = 0 , hi = 1e9; 
       for(int i = 0 ;i < 5000 ; ++ i){
              cd A , B ; 
              double mid = (lo + hi) / 2.0; 
              double th = 2.0 * pi / n; 

              for(int j = 0 ;j < 2 ; ++ j){
                     cd y = cd( mid * cos(th * j) , mid * sin(th*j)) ; 
                     if(j == 0) A = y ; 
                     else if(j == 1) B = y ; 
              }     

              if( norm(A - B) - EPS > l * l ){
                     hi = mid ; 
              }else lo = mid; 
       }
       return lo ; 
}

int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);
#ifndef ONLINE_JUDGE
#endif

       cin >> n >> l >> k;  

       L = getl(0) ; 
       double lo = 0, hi = 1e9;
       // cout << k / 
       // cout << (solve(2.302)) ; 
       // return 0; 
       cout << fixed << setprecision(3) ; 
       for (int i = 0; i < 5000; ++i)
       {
              long double mid = (lo + hi) / 2.0;
              
              double x = solve(mid);
              double cir = 1.0 * pi * mid * mid ; 
              if (x * 10000.0 >= 1.0 * k * cir )
              {
                     lo = mid;
              }
              else
                     hi = mid;
       }
       cout << lo;
       return 0;
}
Copy
I Shot the Sheriff Mohamed.Sobhy
GNU G++17
2 ms
360 KB
Wrong Answer