https://codeforces.com/problemset/problem/1354/C2
直接上旋转卡壳发现只能解决c1,解决不了c2。。。
搞了半天想到一个很简单的做法
我们知道正多边形每条边的外角都是(360/2n)度,先把这2n个点求出来,那么令第一个点在(0,0)不懂,其他所有点绕0,0旋转,看用一个与坐标轴平行的正方形去框的长度是多少,也就是max(max(y),max(x)-min(x))。
这个东西通过画图可知三分角度是可以求极值的
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps=1e-12;
const double pi=acos(-1.0);
inline int sgn(double x)
{
if(fabs(x)<eps) return 0;
if(x<0)
return -1;
else
return 1;
}
struct point
{
double x,y;
point(double a=0,double b=0)
{
x=a;y=b;
}
point operator + (const point &b)const
{
return point(x+b.x,y+b.y);
}
point operator - (const point &b)const
{
return point(x-b.x,y-b.y);
}
void transxy(double sinb,double cosb)
{ //????????,????sin,cos
double tx=x,ty=y;
x=tx*cosb-ty*sinb;
y=tx*sinb+ty*cosb;
}
void transxy(double b)//????????b????
{
double tx=x,ty=y;
x=tx*cos(b)-ty*sin(b);
y=tx*sin(b)+ty*cos(b);
}
double norm()
{
return sqrt(x*x+y*y);
}
inline double norm2()
{
return x*x+y*y;
}
};
struct polygon_convex
{
vector<point> P;
polygon_convex(int size=0)
{
P.resize(size);
}
};
const int maxl=3e5+10;
int n,m,cas,k;
int a[maxl],b[maxl];
char s[maxl];
bool in[maxl];
polygon_convex p;
point tmp[maxl];
double ans;
inline void prework()
{
scanf("%d",&n);
p.P.clear();
double b=pi/n;
double cosb=cos(b),sinb=sin(b);
point vec=point(1,0),now=point(0,0);
p.P.push_back(now);
for(int i=2;i<=2*n;i++)
{
now=now+vec;
p.P.push_back(now);
vec.transxy(sinb,cosb);
}
}
inline double calc(double mid)
{
double mxx=0,mxy=0;
int n=0;
for(auto q: p.P)
{
tmp[++n]=q;
tmp[n].transxy(mid);
}
double l=0,r=0;
for(int i=1;i<=n;i++)
{
mxy=max(mxy,tmp[i].y);
l=min(l,tmp[i].x);
r=max(r,tmp[i].x);
}
return max(r-l,mxy);
}
inline void mainwork()
{
int fir,sec;
double l=0,r=pi/n,mid,midd,t,td;
while(l+eps<r)
{
mid=(l+r)/2;midd=(mid+r)/2;
t=calc(mid),td=calc(midd);
if(t>td)
l=mid;
else
r=midd;
}
ans=t;
}
inline void print()
{
printf("%.8f\n",ans);
}
int main()
{
int t=1;
scanf("%d",&t);
for(cas=1;cas<=t;cas++)
{
prework();
mainwork();
print();
}
return 0;
}