首页 > 学院 > 开发设计 > 正文

[BZOJ1913][Apio2010]signaling 信号覆盖(计算几何+组合数学)

2019-11-11 02:13:47
字体:
来源:转载
供稿:网友

题目描述

传送门

题解

非常神奇的一道思路题,刚开始只会sb暴力 这篇题解讲得非常好orz:http://blog.csdn.net/qpswwww/article/details/45334033

代码

#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>using namespace std;#define N 1505const double pi=acos(-1.0);const double eps=1e-9;int dcmp(double x){ if (x<=eps&&x>=-eps) return 0; return (x>0)?1:-1;}struct Point{double x,y;};int n;double ang[N+N],ao,tu,ans;Point p[N];double C(int n,int m){ if (m>n) return 0.0; double ans=1.0; for (int i=n-m+1;i<=n;++i) ans*=(double)i; for (int i=1;i<=m;++i) ans/=(double)i; return ans;}double calc(int id){ int cnt=0; for (int i=1;i<=n;++i) if (id!=i) ang[++cnt]=atan2(p[i].y-p[id].y,p[i].x-p[id].x); sort(ang+1,ang+cnt+1); for (int i=1;i<=cnt;++i) ang[cnt+i]=ang[i]+2*pi; double ans=0; int l=1,r=1; while (l<=cnt) { r=max(r,l+1); while (r<=cnt*2&&ang[r]<ang[l]+pi) ++r; ans+=C(r-l-1,2); ++l; } return C(n-1,3)-ans;}int main(){ scanf("%d",&n); if (n==3) {puts("3.000000");return 0;} for (int i=1;i<=n;++i) scanf("%lf%lf",&p[i].x,&p[i].y); for (int i=1;i<=n;++i) ao+=calc(i); tu=C(n,4)-ao; ans=(ao+2*tu)/C(n,3)+3.0; PRintf("%.6lf/n",ans);}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表