您的位置:首页 > 其它

[几何] Codeforces 772B VK Cup 2017 - Round 2 B. Volatile Kite

2017-06-13 22:39 302 查看


那么问题来了 O(n)判到底对不对

#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef double ld;

struct P{
ld x,y;
void read() { double _x,_y; scanf("%lf%lf",&_x,&_y); x=_x; y=_y; }
P(ld x=0,ld y=0):x(x),y(y) { }
P rot(ld A){ return P(x*cos(A)-y*sin(A),x*sin(A)+y*cos(A)); }
ld dist(){ return sqrt(x*x+y*y); }
friend P operator + (P A,P B) { return P(A.x+B.x,A.y+B.y); }
friend P operator - (P A,P B) { return P(A.x-B.x,A.y-B.y); }
friend ld operator * (P A,P B) { return A.x*B.y-B.x*A.y; }
friend P operator * (P A,ld B) { return P(A.x*B,A.y*B); }
friend P operator / (P A,ld B) { return P(A.x/B,A.y/B); }
friend ld dist(P A,P B){ return (A-B).dist(); }
}p[1005];
int n;

inline ld solve(P A,P B,P C){
return fabs((A-C)*(B-C))/((B-A).dist());
}

int main(){
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
scanf("%d",&n);
for (int i=0;i<n;i++) p[i].read();
ld ans=1e15;
for (int i=0;i<n;i++)
ans=min(ans,solve(p[(i+n-1)%n],p[(i+1)%n],p[i]));
printf("%.10lf\n",ans/2);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐