【NOI2018模拟】Yja

【NOI2018模拟】Yja

Description

  在平面上找\(n\)个点,要求这 \(n\)个点离原点的距离分别为 \(r1,r2,...,rn\) 。最大化这\(n\) 个点构成的凸包面积,凸包上的点的顺序任意。
  注意:不要求点全部在凸包上。

Input

  第一行一个整数 \(n\)
  接下来一行$ n$ 个整数依次表示 \(ri\)

Output

  输出一个实数表示答案,要求绝对误差或相对误差 \(≤ 10^{-6}\)

Sample Input

4
5
8
58
85

Sample Output

2970

Hint

【数据范围与约定】
  对于前 \(20%\) 的数据,\(n ≤ 3\)
  对于前$ 40%$ 的数据,\(n ≤ 4\)
  对于另 \(20%\) 的数据,\(r1 = r2 = ... = rn\)
  对于 \(100%\) 的数据,\(1 ≤ n ≤ 8,1 ≤ ri ≤ 1000\)

前置知识:拉格朗日乘数法:

https://blog.csdn.net/the_lastest/article/details/78136692

我们可以用\(\sum_{i=1}^n i!\)的复杂度枚举凸包的所有情况。因为肯定是选最长的\(i\)条线段,所以不需要\(2^i\)枚举集合。

题目中的几个偏导方程是:
\[ \begin{align} \theta _1+\theta_2+\dots+\theta_n=0\\ r_i*r_{i\%n+1}*cos(\theta _i)+\lambda=0\\ \end{align} \]
由于\(cos(\theta)\)\([-\pi,\pi]\)之间是单调递减的,所以我们可以二分\(\lambda\)然后反解出\(\theta_i\)并检验是否满足题意。

如果某个\(\theta_i\)\(0\)非常接近就应该舍去。

代码:

#include<bits/stdc++.h>
#define ll long long
#define N 10
#define eps 1e-9

using namespace std;
inline int Get() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}while('0'<=ch&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}

int n;
int r[N];
bool cmp(int a,int b) {return a>b;}
int st[N];
double val[N];
double ans;

const double pi=acos(-1);

double chk(int n,double ans) {
    double tot=0;
    for(int i=1;i<=n;i++) {
        if(fabs(ans)>fabs(val[i])) {
            exit(-1);
        }
        tot+=acos(-ans/val[i]);
    }
    if(tot>2*pi+eps) return 1;
    else return 0;
}

int q[N];
double solve(int n) {
    double l,r,mid;
    double ans=0;
    while(1) {
        for(int i=1;i<=n;i++) st[i]=::r[q[i]];
        for(int i=1;i<n;i++) val[i]=st[i]*st[i+1];
        val[n]=st[n]*st[1];
        l=-1e9,r=1e9;
        for(int i=1;i<=n;i++) {
            l=max(l,-val[i]);
            r=min(r,val[i]);
        }
        while(l+1e-5<r) {
            mid=(l+r)/2.0;
            if(chk(n,mid)) r=mid-eps;
            else l=mid;
        }
        double now=0;
        double angle_tot=0;
        for(int i=1;i<=n;i++) {
            double angle=acos(-l/val[i]);
            if(angle<eps) now-=1e9;
            angle_tot+=angle;
            now+=val[i]*sin(angle);
        }
        ans=max(ans,now);
        if(!next_permutation(q+1,q+1+n)) break;
    }
    return ans;
}

int main() {
    n=Get();
    for(int i=1;i<=n;i++) r[i]=Get();
    sort(r+1,r+1+n,cmp);
    for(int i=3;i<=n;i++) {
        for(int j=1;j<=i;j++) q[j]=j;
        ans=max(ans,solve(i));
    }
    cout<<fixed<<setprecision(7)<<ans/2.0;
    return 0;
}

转载于:https://www.cnblogs.com/hchhch233/p/10505465.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值