LOJ#2190. 「SHOI2014」信号增幅仪(最小圆覆盖)

题面

传送门

题解

我连椭圆是个啥都不知道导致这么简单一道题我一点思路都没有……

我们把坐标系旋转一下,让半长轴成为新的\(x\)轴,也就是说所有点都绕原点逆时针旋转\(360-a\)度,然后再把所有点的\(x\)坐标变为原来的\({1\over p}\),跑一个最小圆覆盖就行了

//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
double readdb()
{
R double x=0,y=0.1,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(x=ch-'0';(ch=getc())>='0'&&ch<='9';x=x*10+ch-'0');
for(ch=='.'&&(ch=getc());ch>='0'&&ch<='9';x+=(ch-'0')*y,y*=0.1,ch=getc());
return x*f;
}
const int N=1e5+5;const double eps=1e-6,Pi=acos(-1.0);
inline double reps(){return (1.0*rand()/RAND_MAX-0.5)*eps;}
inline int sgn(R double x){return x<-eps?-1:x>eps;}
struct node{
double x,y;
inline node(){}
inline node(R double xx,R double yy):x(xx),y(yy){}
inline node operator +(const node &b)const{return node(x+b.x,y+b.y);}
inline node operator -(const node &b)const{return node(x-b.x,y-b.y);}
inline double operator *(const node &b)const{return x*b.y-y*b.x;}
inline node operator *(const double &b)const{return node(x*b,y*b);}
inline double operator ^(const node &b)const{return x*b.x+y*b.y;}
inline double len2(){return x*x+y*y;}
inline node rot(R double s,R double c){return node(x*c-y*s,x*s+y*c);}
inline node rot90(){return node(-y,x);}
inline void shake(){x+=reps(),y+=reps();}
}p[N],o;
struct Line{
node p,v;
inline Line(){}
inline Line(R node pp,R node vv):p(pp),v(vv){}
friend node cross(const Line &a,const Line &b){return a.p+a.v*(b.v*(b.p-a.p)/(b.v*a.v));}
};
node circle(const node &a,const node &b,const node &c){
return cross(Line((a+b)*0.5,(b-a).rot90()),Line((a+c)*0.5,(c-a).rot90()));
}
int n;double s,c,a,b;
double calc(){
double r=0;o=node(0,0);
random_shuffle(p+1,p+1+n);
fp(i,1,n)if(sgn((p[i]-o).len2()-r)>0){
o=p[i],r=0;
fp(j,1,i-1)if(sgn((p[j]-o).len2()-r)>0){
o=(p[i]+p[j])*0.5,r=(p[j]-o).len2();
fp(k,1,j-1)if(sgn((p[k]-o).len2()-r)>0)
o=circle(p[i],p[j],p[k]),r=(p[k]-o).len2();
}
}
return sqrt(r);
}
int main(){
srand(20030719);
// freopen("testdata.in","r",stdin);
n=read();
fp(i,1,n)p[i].x=readdb(),p[i].y=readdb(),p[i].shake();
b=read(),a=read(),b=(360-b)/180.0*Pi,s=sin(b),c=cos(b),a=1.0/a;
fp(i,1,n)p[i]=p[i].rot(s,c);
fp(i,1,n)p[i].x=p[i].x*a;
printf("%.3lf\n",calc());
return 0;
}
上一篇:数据库字典 sql


下一篇:JS代码的加载