【BZOJ】1913: [Apio2010]signaling 信号覆盖(计算几何+计数)

题目

传送门:QWQ

 

 

分析

人类智慧题,不会做。。。。。。

 详细题解1      详细题解2

总体思路是考虑四边形 

讨论凹四边形凸四边形,最后加一个单调性优化省掉个$ O(n) $

 

 

代码

代码感觉好短啊

//https://blog.csdn.net/regina8023/article/details/45556321
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1550;
const double PI=acos(-1);
struct Point{
    double x,y;
}p[maxn]; 
LL C(int n,int m){
    LL ans=1;
    for (int i=1;i<=m;i++)
        ans=1LL*ans*(n-i+1);
    for (int i=2;i<=m;i++)
        ans/=i;
    return ans;
}
double a[2*maxn];
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    double anss=0;
    for(int i=1;i<=n;i++){
        int tot=0;
        for(int j=1;j<=n;j++){
            if(i==j) continue;
            a[++tot]=atan2(p[j].x-p[i].x,p[j].y-p[i].y);
            if (a[tot]<0) a[tot]+=PI*2;
        }
        sort(a+1,a+n);
        for(int j=0;j<n;j++){
            a[j+n]=a[j+1]+2*PI;
        }
        int now=1; LL ans=0;
        for(int j=1;j<n;j++){
            while(now<n+n-2 && a[now+1]-a[j]<PI){
                now++;
            }
            if(now-j>1)ans+=C(now-j,2);
        }//这里计算的是凸四边形 
        anss+=(double)(C(n-1,3)-ans);//凹四边形 
    }
    anss=(double)(anss+2*(C(n,4)-anss))/C(n,3) + 3;
    printf("%.6lf\n",anss);
    return 0;
}

 

 

 

posted @ 2018-06-14 00:39  noble_(noblex)  阅读(136)  评论(0编辑  收藏  举报
/* */