# Codeforces Gym: 101484 E. Double Fence

0

Solution Idea:

Let P1 and P2 be respectively the set of points of the first polygon and the set of points of the second polygon. Let ch(X) be the set of points on the convex hull of the set of points X, including colinear points on the edges. A polygon is strictly inside the other if ch(P1 U P2 equals to P1 or P2.
```
#include&lt;vector&gt;
#include&lt;list&gt;
#include&lt;map&gt;
#include&lt;set&gt;
#include&lt;deque&gt;
#include&lt;queue&gt;
#include&lt;stack&gt;
#include&lt;bitset&gt;
#include&lt;algorithm&gt;
#include&lt;functional&gt;
#include&lt;numeric&gt;
#include&lt;utility&gt;
#include&lt;iostream&gt;
#include&lt;sstream&gt;
#include&lt;iomanip&gt;
#include&lt;cstdio&gt;
#include&lt;cmath&gt;
#include&lt;cstdlib&gt;
#include&lt;cctype&gt;
#include&lt;string&gt;
#include&lt;cstring&gt;
#include&lt;cstdio&gt;
#include&lt;cmath&gt;
#include&lt;cstdlib&gt;
#include&lt;ctime&gt;
#include&lt;climits&gt;
#include&lt;complex&gt;
#define mp make_pair
#define pb push_back
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
const double inf=1e20;
const int maxp=200007;
int dblcmp(double d)
{
if (fabs(d)&lt;eps)return 0;
return d&gt;eps?1:-1;
}
inline double sqr(double x)
{
return x*x;
}

struct point
{
double x,y;
point()             {                                    }
point(double _x,double _y)
{
x = _x;
y = _y;
}
void input()
{
scanf(&quot;%lf%lf&quot;,&amp;x,&amp;y);
}
void output()
{
printf(&quot;%.2f %.2f\n&quot;,x,y);
}
bool operator==(point a)const
{
return dblcmp(a.x - x) == 0 &amp;&amp; dblcmp(a.y - y) == 0;
}
bool operator&lt;(point a)const
{
return dblcmp(a.x - x) == 0 ? dblcmp(y - a.y) &lt; 0 : x &lt; a.x;
}
point operator-(point a)const
{
return point(x-a.x, y-a.y);
}
double len()
{
return hypot(x, y);
}
double len2()
{
return x * x + y * y;
}
double distance(point p)
{
return hypot(x - p.x, y - p.y);
}
{
return point(x + p.x, y + p.y);
}
point sub(point p)
{
return point(x - p.x, y - p.y);
}
point mul(double b)
{
return point(x * b, y * b);
}
point div(double b)
{
return point(x / b, y / b);
}
double dot(point p)
{
return x*p.x+y*p.y;
}
double det(point p)
{
return x*p.y-y*p.x;
}
{
point p=*this;
return fabs(atan2(fabs(a.sub(p).det(b.sub(p))),a.sub(p).dot(b.sub(p))));
}
point trunc(double r)
{
double l=len();
if (!dblcmp(l))return *this;
r/=l;
return point(x*r,y*r);
}
point rotleft()
{
return point(-y,x);
}
point rotright()
{
return point(y,-x);
}
point rotate(point p,double angle)
{
point v=this-&gt;sub(p);
double c=cos(angle),s=sin(angle);
return point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
}
};

struct line
{
point a,b;
line()              {                                    }
line(point _a,point _b)
{
a=_a;
b=_b;
}
bool operator==(line v)
{
return (a==v.a)&amp;&amp;(b==v.b);
}
line(point p,double angle)
{
a=p;
if (dblcmp(angle-pi/2)==0)
{
}
else
{
}
}
//ax+by+c=0
line(double _a,double _b,double _c)
{
if (dblcmp(_a)==0)
{
a=point(0,-_c/_b);
b=point(1,-_c/_b);
}
else if (dblcmp(_b)==0)
{
a=point(-_c/_a,0);
b=point(-_c/_a,1);
}
else
{
a=point(0,-_c/_b);
b=point(1,(-_c-_a)/_b);
}
}
void input()
{
a.input();
b.input();
}
{
if(b&lt;a)swap(a,b);
}
double length()
{
return a.distance(b);
}
double angle()
{
double k=atan2(b.y-a.y,b.x-a.x);
if (dblcmp(k)&lt;0)k+=pi;
if (dblcmp(k-pi)==0)k-=pi;
return k;
}
int relation(point p)
{
int c=dblcmp(p.sub(a).det(b.sub(a)));
if (c&lt;0)return 2;
if (c&gt;0)return 1;
return 0;
}
bool pointonseg(point p)
{
return dblcmp(p.sub(a).det(b.sub(a)))==0&amp;&amp;dblcmp(p.sub(a).dot(p.sub(b)))&lt;=0;
}
bool parallel(line v)
{
return dblcmp(b.sub(a).det(v.b.sub(v.a)))==0;
}
int segcrossseg(line v)
{
int d1=dblcmp(b.sub(a).det(v.a.sub(a)));
int d2=dblcmp(b.sub(a).det(v.b.sub(a)));
int d3=dblcmp(v.b.sub(v.a).det(a.sub(v.a)));
int d4=dblcmp(v.b.sub(v.a).det(b.sub(v.a)));
if ((d1^d2)==-2&amp;&amp;(d3^d4)==-2)return 2;
return (d1==0&amp;&amp;dblcmp(v.a.sub(a).dot(v.a.sub(b)))&lt;=0||
d2==0&amp;&amp;dblcmp(v.b.sub(a).dot(v.b.sub(b)))&lt;=0||
d3==0&amp;&amp;dblcmp(a.sub(v.a).dot(a.sub(v.b)))&lt;=0||
d4==0&amp;&amp;dblcmp(b.sub(v.a).dot(b.sub(v.b)))&lt;=0);
}
int segcrossseg_inside(line v)
{
if(v.pointonseg(a) || v.pointonseg(b) || pointonseg(v.a) || pointonseg(v.b)) return 0;
int d1=dblcmp(b.sub(a).det(v.a.sub(a)));
int d2=dblcmp(b.sub(a).det(v.b.sub(a)));
int d3=dblcmp(v.b.sub(v.a).det(a.sub(v.a)));
int d4=dblcmp(v.b.sub(v.a).det(b.sub(v.a)));
if ((d1^d2)==-2&amp;&amp;(d3^d4)==-2)return 1;
return (d1==0&amp;&amp;dblcmp(v.a.sub(a).dot(v.a.sub(b)))&lt;=0||
d2==0&amp;&amp;dblcmp(v.b.sub(a).dot(v.b.sub(b)))&lt;=0||
d3==0&amp;&amp;dblcmp(a.sub(v.a).dot(a.sub(v.b)))&lt;=0||
d4==0&amp;&amp;dblcmp(b.sub(v.a).dot(b.sub(v.b)))&lt;=0);
}
int linecrossseg(line v) //*this seg v line
{
int d1=dblcmp(b.sub(a).det(v.a.sub(a)));
int d2=dblcmp(b.sub(a).det(v.b.sub(a)));
if ((d1^d2)==-2)return 2;
return (d1==0||d2==0);
}
int linecrossline(line v)
{
if ((*this).parallel(v))
{
return v.relation(a)==3;
}
return 2;
}
point crosspoint(line v)
{
double a1=v.b.sub(v.a).det(a.sub(v.a));
double a2=v.b.sub(v.a).det(b.sub(v.a));
return point((a.x*a2-b.x*a1)/(a2-a1),(a.y*a2-b.y*a1)/(a2-a1));
}
double dispointtoline(point p)
{
return fabs(p.sub(a).det(b.sub(a)))/length();
}
double dispointtoseg(point p)
{
if (dblcmp(p.sub(b).dot(a.sub(b)))&lt;0||dblcmp(p.sub(a).dot(b.sub(a)))&lt;0)
{
return min(p.distance(a),p.distance(b));
}
return dispointtoline(p);
}
point lineprog(point p)
{
}
point symmetrypoint(point p)
{
point q=lineprog(p);
return point(2*q.x-p.x,2*q.y-p.y);
}
};

struct polygon
{
int n=0;
point p[maxp];
line l[maxp];
void input(int _n)
{
n=_n;
for (int i=0; i&lt;n; i++)   p[i].input();
}
{
p[n++]=q;
}
void getline()
{
for (int i=0; i&lt;n; i++)
l[i]=line(p[i],p[(i+1)%n]);
}
struct cmp
{
point p;
cmp(const point &amp;p0)
{
p=p0;
}
bool operator()(const point &amp;aa,const point &amp;bb)
{
point a=aa,b=bb;
int d=dblcmp(a.sub(p).det(b.sub(p)));
if (d==0)
return dblcmp(a.distance(p)-b.distance(p))&lt;0;
return d&gt;0;
}
};
void norm()
{
point mi=p[0];
for (int i=1; i&lt;n; i++)mi=min(mi,p[i]);
sort(p,p+n,cmp(mi));
}
void getconvex(polygon &amp;convex)
{
int i;
sort(p,p+n);
convex.n=n;
for (i=0; i&lt;min(n,2); i++) convex.p[i]=p[i];
if (n&lt;=2)return;
int &amp;top=convex.n;
top=1;
for (i=2; i&lt;n; i++)
{
while (top&amp;&amp;convex.p[top].sub(p[i]).det(convex.p[top-1].sub(p[i]))&lt;0)
top--;
convex.p[++top]=p[i];
}
int temp=top;
convex.p[++top]=p[n-2];
for (i=n-3; i&gt;=0; i--)
{
while (top!=temp&amp;&amp;convex.p[top].sub(p[i]).det(convex.p[top-1].sub(p[i]))&lt;0)
top--;
convex.p[++top]=p[i];
}
}
bool isconvex()
{
bool s[3];
memset(s,0,sizeof(s));
int i,j,k;
for (i=0; i&lt;n; i++)
{
j=(i+1)%n;
k=(j+1)%n;
s[dblcmp(p[j].sub(p[i]).det(p[k].sub(p[i])))+1]=1;
if (s[0]&amp;&amp;s[2])return 0;
}
return 1;
}

};

int main()
{
int n,m;
scanf(&quot;%d %d&quot;,&amp;n,&amp;m);
polygon a,b,ab;
for(int i=0; i&lt;n; i++)
{
double x,y;
scanf(&quot;%lf %lf&quot;,&amp;x,&amp;y);
}
for(int i=0; i&lt;m; i++)
{
double x,y;
scanf(&quot;%lf %lf&quot;,&amp;x,&amp;y);
}

polygon cha, chb, chab;

//    a.getconvex(cha);
//    b.getconvex(chb);
ab.getconvex(chab);

sort(a.p,a.p+a.n);
sort(b.p,b.p+b.n);
sort(chab.p,chab.p+chab.n);

//       cout&lt;&lt;ab.n&lt;&lt;endl;
//    for(int i=0;i&lt;ab.n;i++)
//        cout&lt;&lt;ab.p[i].x&lt;&lt;&quot; &quot;&lt;&lt;ab.p[i].y&lt;&lt;endl;
//
//    cout&lt;&lt;&quot;---------------------&quot;&lt;&lt;endl;
//
//    cout&lt;&lt;chab.n&lt;&lt;endl;
//    for(int i=0;i&lt;chab.n;i++)
//        cout&lt;&lt;chab.p[i].x&lt;&lt;&quot; &quot;&lt;&lt;chab.p[i].y&lt;&lt;endl;

if(a.n==chab.n)
{
bool check=0;
for(int i=0; i&lt;a.n; i++)
if(a.p[i]==chab.p[i]) continue;
else
{
check=1;
break;
}
if(check==0)
{
printf(&quot;YES\n&quot;);
return 0;
}
}

if(b.n==chab.n)
{
bool check=0;
for(int i=0; i&lt;b.n; i++)
if(b.p[i]==chab.p[i]) continue;
else
{
check=1;
break;
}
if(check==0)
{
printf(&quot;YES\n&quot;);
return 0;
}
}

printf(&quot;NO\n&quot;);
return 0;

}

```

# UVa 438 – The Circumference of the Circle

0

```
#include &lt;bits/stdc++.h&gt;

#define pii              pair &lt;int,int&gt;
#define pll              pair &lt;long long,long long&gt;
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define EPS              10E-10
#define ff               first
#define ss               second
#define sqr(x)           (x)*(x)
#define D(x)             cout&lt;&lt;#x &quot; = &quot;&lt;&lt;(x)&lt;&lt;endl
#define VI               vector &lt;int&gt;
#define DBG              pf(&quot;Hi\n&quot;)
#define MOD              1000000007
#define CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SZ(a)            (int)a.size()
#define sf(a)            scanf(&quot;%d&quot;,&amp;a)
#define sfl(a)           scanf(&quot;%lld&quot;,&amp;a)
#define sff(a,b)         scanf(&quot;%d %d&quot;,&amp;a,&amp;b)
#define sffl(a,b)        scanf(&quot;%lld %lld&quot;,&amp;a,&amp;b)
#define sfff(a,b,c)      scanf(&quot;%d %d %d&quot;,&amp;a,&amp;b,&amp;c)
#define sfffl(a,b,c)     scanf(&quot;%lld %lld %lld&quot;,&amp;a,&amp;b,&amp;c)
#define stlloop(v)       for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define loop(i,n)        for(int i=0;i&lt;n;i++)
#define loop1(i,n)       for(int i=1;i&lt;=n;i++)
#define REP(i,a,b)       for(int i=a;i&lt;b;i++)
#define RREP(i,a,b)      for(int i=a;i&gt;=b;i--)
#define TEST_CASE(t)     for(int z=1;z&lt;=t;z++)
#define PRINT_CASE       printf(&quot;Case %d: &quot;,z)
#define LINE_PRINT_CASE  printf(&quot;Case %d:\n&quot;,z)
#define CASE_PRINT       cout&lt;&lt;&quot;Case &quot;&lt;&lt;z&lt;&lt;&quot;: &quot;
#define all(a)           a.begin(),a.end()
#define intlim           2147483648
#define infinity         (1&lt;&lt;28)
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))

using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//int Set(int N,int pos){return N=N | (1&lt;&lt;pos);}
//int reset(int N,int pos){return N= N &amp; ~(1&lt;&lt;pos);}
//bool check(int N,int pos){return (bool)(N &amp; (1&lt;&lt;pos));}
/*------------------------------------------------*/

double dist(double x1, double y1, double x2, double y2)
{
return sqrt(sqr(x1-x2)+sqr(y1-y2));
}

int main()
{

///freopen(&quot;in.txt&quot;,&quot;r&quot;,stdin);
///freopen(&quot;out.txt&quot;,&quot;w&quot;,stdout);

double x1,y1,x2,y2,x3,y3;
while(cin&gt;&gt;x1&gt;&gt;y1&gt;&gt;x2&gt;&gt;y2&gt;&gt;x3&gt;&gt;y3)
{
double a,b,c;

//calculating the three side of the triangle

a=dist(x1,y1,x2,y2);
b=dist(x2,y2,x3,y3);
c=dist(x1,y1,x3,y3);

// calculating the sub perimeter

double s=(a+b+c)/2.0;

// calculating the area of the triangle.

double area=sqrt(s*(s-a)*(s-b)*(s-c));

// calculating radius using formula area= (a*b*c)/(2*R) ; here R = diameter

double r=(a*b*c)/(4.0*area);

cout&lt;&lt;setprecision(2)&lt;&lt;fixed&lt;&lt;Pi*2.0*r&lt;&lt;endl;

}

return 0;
}

```

# Light OJ: 1137 – Expanding Rods

0

Solution Idea: The problem become easy for binary search if you find any way to calculate the radius of the circle which contains that arc. If you can do this then you can calculate the arc length using the formula S=R*theta. where S=arc length and R= calculated radius.

Now we can guess the ans H through binary search and adjust on the basis of calculated arc length of that taken H and original final arc length.

Here is a link which contains the formula and formula proof for calculate Radius R .

```
#include &lt;bits/stdc++.h&gt;

#define pii              pair &lt;int,int&gt;
#define pll              pair &lt;long long,long long&gt;
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define EPS              10E-10
#define ff               first
#define ss               second
#define sqr(x)           (x)*(x)
#define D(x)             cout&lt;&lt;#x &quot; = &quot;&lt;&lt;(x)&lt;&lt;endl
#define VI               vector &lt;int&gt;
#define DBG              pf(&quot;Hi\n&quot;)
#define MOD              1000000007
#define CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SZ(a)            (int)a.size()
#define sf(a)            scanf(&quot;%d&quot;,&amp;a)
#define sfl(a)           scanf(&quot;%lld&quot;,&amp;a)
#define sff(a,b)         scanf(&quot;%d %d&quot;,&amp;a,&amp;b)
#define sffl(a,b)        scanf(&quot;%lld %lld&quot;,&amp;a,&amp;b)
#define sfff(a,b,c)      scanf(&quot;%d %d %d&quot;,&amp;a,&amp;b,&amp;c)
#define sfffl(a,b,c)     scanf(&quot;%lld %lld %lld&quot;,&amp;a,&amp;b,&amp;c)
#define stlloop(v)       for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define loop(i,n)        for(int i=0;i&lt;n;i++)
#define loop1(i,n)       for(int i=1;i&lt;=n;i++)
#define REP(i,a,b)       for(int i=a;i&lt;b;i++)
#define RREP(i,a,b)      for(int i=a;i&gt;=b;i--)
#define TEST_CASE(t)     for(int z=1;z&lt;=t;z++)
#define PRINT_CASE       printf(&quot;Case %d: &quot;,z)
#define CASE_PRINT       cout&lt;&lt;&quot;Case &quot;&lt;&lt;z&lt;&lt;&quot;: &quot;
#define all(a)           a.begin(),a.end()
#define intlim           2147483648
#define infinity         (1&lt;&lt;28)
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))

using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//int Set(int N,int pos){return N=N | (1&lt;&lt;pos);}
//int reset(int N,int pos){return N= N &amp; ~(1&lt;&lt;pos);}
//bool check(int N,int pos){return (bool)(N &amp; (1&lt;&lt;pos));}
/*------------------------------------------------*/

int main()
{

///freopen(&quot;in.txt&quot;,&quot;r&quot;,stdin);
///freopen(&quot;out.txt&quot;,&quot;w&quot;,stdout);

int t;
sf(t);
TEST_CASE(t)
{
double l,n,c;
sc(&quot;%lf %lf %lf&quot;,&amp;l,&amp;n,&amp;c);
double final_length=(1.0+n*c)*l;

double lo=0.0, hi=l;

for(int i=0;i&lt;60;i++)
{
double mid=(lo+hi)/2.0;
if(temp_length&gt;=final_length)
hi=mid;
else
lo=mid;
}

PRINT_CASE;
pf(&quot;%.10lf\n&quot;,lo);

}

return 0;
}

```

# Light OJ: 1062 – Crossed Ladders

4

```
#include &lt;bits/stdc++.h&gt;

#define pii              pair &lt;int,int&gt;
#define pll              pair &lt;long long,long long&gt;
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define EPS              10E-10
#define ff               first
#define ss               second
#define sqr(x)           (x)*(x)
#define D(x)             cout&lt;&lt;#x &quot; = &quot;&lt;&lt;(x)&lt;&lt;endl
#define VI               vector &lt;int&gt;
#define DBG              pf(&quot;Hi\n&quot;)
#define MOD              1000000007
#define CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SZ(a)            (int)a.size()
#define sf(a)            scanf(&quot;%d&quot;,&amp;a)
#define sfl(a)           scanf(&quot;%lld&quot;,&amp;a)
#define sff(a,b)         scanf(&quot;%d %d&quot;,&amp;a,&amp;b)
#define sffl(a,b)        scanf(&quot;%lld %lld&quot;,&amp;a,&amp;b)
#define sfff(a,b,c)      scanf(&quot;%d %d %d&quot;,&amp;a,&amp;b,&amp;c)
#define sfffl(a,b,c)     scanf(&quot;%lld %lld %lld&quot;,&amp;a,&amp;b,&amp;c)
#define stlloop(v)       for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define loop(i,n)        for(int i=0;i&lt;n;i++)
#define loop1(i,n)       for(int i=1;i&lt;=n;i++)
#define REP(i,a,b)       for(int i=a;i&lt;b;i++)
#define RREP(i,a,b)      for(int i=a;i&gt;=b;i--)
#define TEST_CASE(t)     for(int z=1;z&lt;=t;z++)
#define PRINT_CASE       printf(&quot;Case %d: &quot;,z)
#define CASE_PRINT       cout&lt;&lt;&quot;Case &quot;&lt;&lt;z&lt;&lt;&quot;: &quot;
#define all(a)           a.begin(),a.end()
#define intlim           2147483648
#define infinity         (1&lt;&lt;28)
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))

using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//int Set(int N,int pos){return N=N | (1&lt;&lt;pos);}
//int reset(int N,int pos){return N= N &amp; ~(1&lt;&lt;pos);}
//bool check(int N,int pos){return (bool)(N &amp; (1&lt;&lt;pos));}
/*------------------------------------------------*/

int main()
{

///freopen(&quot;in.txt&quot;,&quot;r&quot;,stdin);
///freopen(&quot;out.txt&quot;,&quot;w&quot;,stdout);

int t;
sf(t);
TEST_CASE(t)
{
double x,y,c;
sc(&quot;%lf %lf %lf&quot;,&amp;x,&amp;y,&amp;c);

double lo=0.0,hi=max(x,y);

for(int i=0;i&lt;50;i++)
{
double mid=(lo+hi)/2;
double h2=sqrt(sqr(y)-sqr(mid));
double h1=sqrt(sqr(x)-sqr(mid));
double temp_ans=(1.0/h1)+(1.0/h2);
temp_ans=1.0/temp_ans;
if(temp_ans&gt;=c)
lo=mid;
else
hi=mid;
}
PRINT_CASE;
pf(&quot;%.10lf\n&quot;,lo);

}

return 0;
}

```

# Light OJ: 1056 – Olympics

0

Solution Idea:

first determine the radius r. From triangle (r,l/2,w/2 ) we get r^2=(l/2)^2 + (w/2)^2 From (r,r,w) triangle sector angle from cos law. then arc= angle *r so the perimeter of stadium is 2*l + 2*arc and you can get ratio=400/(2*l + 2*arc) then ans is l*ratio , w*ratio .

Formula :

Where angle must be in radian unit.

```
#include &lt;bits/stdc++.h&gt;

#define pii              pair &lt;int,int&gt;
#define pll              pair &lt;long long,long long&gt;
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define EPS              10E-10
#define ff               first
#define ss               second
#define sqr(x)           (x)*(x)
#define D(x)             cout&lt;&lt;#x &quot; = &quot;&lt;&lt;(x)&lt;&lt;endl
#define VI               vector &lt;int&gt;
#define DBG              pf(&quot;Hi\n&quot;)
#define MOD              1000000007
#define CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SZ(a)            (int)a.size()
#define sf(a)            scanf(&quot;%d&quot;,&amp;a)
#define sfl(a)           scanf(&quot;%lld&quot;,&amp;a)
#define sff(a,b)         scanf(&quot;%d %d&quot;,&amp;a,&amp;b)
#define sffl(a,b)        scanf(&quot;%lld %lld&quot;,&amp;a,&amp;b)
#define sfff(a,b,c)      scanf(&quot;%d %d %d&quot;,&amp;a,&amp;b,&amp;c)
#define sfffl(a,b,c)     scanf(&quot;%lld %lld %lld&quot;,&amp;a,&amp;b,&amp;c)
#define stlloop(v)       for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define loop(i,n)        for(int i=0;i&lt;n;i++)
#define loop1(i,n)       for(int i=1;i&lt;=n;i++)
#define REP(i,a,b)       for(int i=a;i&lt;b;i++)
#define RREP(i,a,b)      for(int i=a;i&gt;=b;i--)
#define TEST_CASE(t)     for(int z=1;z&lt;=t;z++)
#define PRINT_CASE       printf(&quot;Case %d: &quot;,z)
#define CASE_PRINT       cout&lt;&lt;&quot;Case &quot;&lt;&lt;z&lt;&lt;&quot;: &quot;
#define all(a)           a.begin(),a.end()
#define intlim           2147483648
#define infinity         (1&lt;&lt;28)
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))

using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//int Set(int N,int pos){return N=N | (1&lt;&lt;pos);}
//int reset(int N,int pos){return N= N &amp; ~(1&lt;&lt;pos);}
//bool check(int N,int pos){return (bool)(N &amp; (1&lt;&lt;pos));}
/*------------------------------------------------*/

int main()
{

///freopen(&quot;in.txt&quot;,&quot;r&quot;,stdin);
///freopen(&quot;out.txt&quot;,&quot;w&quot;,stdout);
int t;
sf(t);
TEST_CASE(t)
{
double l,w;
sc(&quot;%lf : %lf&quot;,&amp;l,&amp;w);
double theta=2.0*atan((w/2.0)/(l/2.0));
double ratio=(400.0/(2*arc_length+2*l));
PRINT_CASE;
pf(&quot;%.10lf %.10lf\n&quot;,l*ratio,w*ratio);
}

return 0;
}

```

# Light OJ: 1043 – Triangle Partitioning

0

```
#include &lt;bits/stdc++.h&gt;

#define pii              pair &lt;int,int&gt;
#define pll              pair &lt;long long,long long&gt;
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define EPS              10E-10
#define ff               first
#define ss               second
#define sqr(x)           (x)*(x)
#define D(x)             cout&lt;&lt;#x &quot; = &quot;&lt;&lt;(x)&lt;&lt;endl
#define VI               vector &lt;int&gt;
#define DBG              pf(&quot;Hi\n&quot;)
#define MOD              1000000007
#define CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SZ(a)            (int)a.size()
#define sf(a)            scanf(&quot;%d&quot;,&amp;a)
#define sfl(a)           scanf(&quot;%lld&quot;,&amp;a)
#define sff(a,b)         scanf(&quot;%d %d&quot;,&amp;a,&amp;b)
#define sffl(a,b)        scanf(&quot;%lld %lld&quot;,&amp;a,&amp;b)
#define sfff(a,b,c)      scanf(&quot;%d %d %d&quot;,&amp;a,&amp;b,&amp;c)
#define sfffl(a,b,c)     scanf(&quot;%lld %lld %lld&quot;,&amp;a,&amp;b,&amp;c)
#define stlloop(v)       for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define loop(i,n)        for(int i=0;i&lt;n;i++)
#define loop1(i,n)       for(int i=1;i&lt;=n;i++)
#define REP(i,a,b)       for(int i=a;i&lt;b;i++)
#define RREP(i,a,b)      for(int i=a;i&gt;=b;i--)
#define TEST_CASE(t)     for(int z=1;z&lt;=t;z++)
#define PRINT_CASE       printf(&quot;Case %d: &quot;,z)
#define CASE_PRINT       cout&lt;&lt;&quot;Case &quot;&lt;&lt;z&lt;&lt;&quot;: &quot;
#define all(a)           a.begin(),a.end()
#define intlim           2147483648
#define infinity         (1&lt;&lt;28)
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))

using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//int Set(int N,int pos){return N=N | (1&lt;&lt;pos);}
//int reset(int N,int pos){return N= N &amp; ~(1&lt;&lt;pos);}
//bool check(int N,int pos){return (bool)(N &amp; (1&lt;&lt;pos));}
/*------------------------------------------------*/

inline double area(double a, double b, double c)
{
double s=(a+b+c)/2.0;
return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main()
{

///freopen(&quot;in.txt&quot;,&quot;r&quot;,stdin);
///freopen(&quot;out.txt&quot;,&quot;w&quot;,stdout);
CIN;
int t;
cin&gt;&gt;t;
TEST_CASE(t)
{
double a,b,c,d;
cin&gt;&gt;a&gt;&gt;b&gt;&gt;c&gt;&gt;d;
double aa,bb,cc,dd;
double lo=0,hi=a;

double triangle_area=area(a,b,c);

for(int i=0;i&lt;60;i++)
{
double mid=(lo+hi)/2.0;
aa=mid;
bb=(b*aa)/a;
cc=(c*aa)/a;
double area1=area(aa,bb,cc);
double area2=triangle_area-area1;
dd=(area1/area2);
if(dd&gt;=d)
hi=mid;
else
lo=mid;
}
CASE_PRINT;
cout&lt;&lt;setprecision(10)&lt;&lt;fixed&lt;&lt;lo&lt;&lt;endl;
}

return 0;
}

```