题目描述

  在平面上找 \(n\) 个点,要求这 \(n\) 个点离原点的距离分别是 \(r_1,r_2,\ldots,r_n\),最大化这 \(n\) 个点构成的土包的面积。这些点的顺序任意。

  \(n\leq 8\)

题解

  先枚举凸包上的点和顺序。

  不妨设 \(r_{n+1}=r_1\)

  面积为:\(\frac{1}{2}(r_1r_2\sin \theta_1+r_2r_3\sin \theta_2 + \cdots + r_nr_{n+1}\theta_n)\)

  那么问题就是最大化 \(r_1r_2\sin \theta_1+r_2r_3\sin \theta_2 + \cdots + r_nr_{n+1}\theta_n\),条件是 \(\theta_1+\theta_2+\cdots \theta_n=2\pi\)

  应用拉格朗日乘数法,有:

\[\begin{cases}
r_1r_2\cos\theta_1=r_2r_3\cos\theta_2=\cdots=r_nr_{n+1}\cos\theta_n&=\lambda\\
\theta_1+\theta_2+\cdots+\theta_n&=2\pi
\end{cases}
\]

  观察到 \(\theta_1,\theta_2,\ldots,\theta_n\) 关于 \(\lambda\)单调,所以可以二分 \(\lambda\) 算出 \(\theta_1,\theta_2,\ldots,\theta_n\)

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
#include<assert.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
if(a>b)
swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
char str[100];
sprintf(str,"%s.in",s);
freopen(str,"r",stdin);
sprintf(str,"%s.out",s);
freopen(str,"w",stdout);
#endif
}
int rd()
{
int s=0,c;
while((c=getchar())<'0'||c>'9');
do
{
s=s*10+c-'0';
}
while((c=getchar())>='0'&&c<='9');
return s;
}
void put(int x)
{
if(!x)
{
putchar('0');
return;
}
static int c[20];
int t=0;
while(x)
{
c[++t]=x%10;
x/=10;
}
while(t)
putchar(c[t--]+'0');
}
int upmin(int &a,int b)
{
if(b<a)
{
a=b;
return 1;
}
return 0;
}
int upmax(int &a,int b)
{
if(b>a)
{
a=b;
return 1;
}
return 0;
}
int n;
const double eps=1e-9;
const double pi=acos(-1);
int a[10];
double ans=0;
auto gao=[](double x){return x<0?x+2*pi:x;};
auto calc=[](double x){double s=0;for(int i=1;i<=n;i++)s+=gao(acos(x/a[i]/a[i+1]));return s;};
void getans()
{
sort(a+1,a+n+1);
a[n+1]=a[1];
do
{
double s=0;
double l=0,r=1e6;
for(int i=1;i<=n;i++)
r=min(r,(double)a[i]*a[i+1]);
l=-r;
if(calc(l)<2*pi||calc(r)>2*pi)
continue;
while(r-l>1e-5)
{
double mid=(l+r)/2;
if(calc(mid)<2*pi)
r=mid;
else
l=mid;
}
for(int i=1;i<=n;i++)
s+=a[i]*a[i+1]*sin(acos(l/a[i]/a[i+1]));
ans=max(ans,s);
}
while(next_permutation(a+2,a+n+1));
}
int r[10];
int main()
{
open("b");
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&r[i]);
if(n<=2)
{
printf("0\n");
return 0;
}
for(int i=1;i<1<<n;i++)
{
::n=0;
for(int j=1;j<=n;j++)
if((i>>(j-1))&1)
a[++::n]=r[j];
if(::n>=3)
getans();
}
printf("%.10lf\n",ans/2);
return 0;
}

【XSY2921】yja 拉格朗日乘法的更多相关文章

  1. 【BZOJ2876】【Noi2012】骑行川藏 拉格朗日乘法

    题目描述 给你 \(n,E,s_i,k_i,v_i'\),要求在 \[ \sum_{i=1}^nk_i{(v_i-v_i')}^2s_i\leq E \] 的前提下最小化 \[ \sum_{i=1}^ ...

  2. 拉格朗日乘法与KKT条件

    问题的引出 给定一个函数\(f\),以及一堆约束函数\(g_1,g_2,...,g_m\)和\(h_1,h_2,...,h_l\).带约束的优化问题可以表示为 \[ \min_{X \in R^n}f ...

  3. SVM-支持向量机总结

    一.SVM简介 (一)Support Vector Machine 支持向量机(SVM:Support Vector Machine)是机器学习中常见的一种分类算法. 线性分类器,也可以叫做感知机,其 ...

  4. 论文解读(LLE)《Nonlinear Dimensionality Reduction by Locally Linear Embedding》and LLE

    论文题目:<Nonlinear Dimensionality Reduction by Locally Linear Embedding > 发表时间:Science  2000 论文地址 ...

  5. Educational Codeforces Round 7 F - The Sum of the k-th Powers 拉格朗日插值

    The Sum of the k-th Powers There are well-known formulas: , , . Also mathematicians found similar fo ...

  6. codeforces 622F. The Sum of the k-th Powers 拉格朗日插值法

    题目链接 求sigma(i : 1 to n)i^k. 为了做这个题这两天真是补了不少数论, 之前连乘法逆元都不知道... 关于拉格朗日插值法, 我是看的这里http://www.guokr.com/ ...

  7. 常系数齐次线性递推 & 拉格朗日插值

    常系数齐次线性递推 具体记在笔记本上了,以后可能补照片,这里稍微写一下,主要贴代码. 概述 形式: \[ h_n = a_1 h_{n-1}+a_2h_{n-2}+...+a_kh_{n-k} \] ...

  8. [模板] 多项式: 乘法/求逆/分治fft/微积分/ln/exp/幂

    多项式 代码 const int nsz=(int)4e5+50; const ll nmod=998244353,g=3,ginv=332748118ll; //basic math ll qp(l ...

  9. 【NOI2018模拟】Yja

    [NOI2018模拟]Yja Description 在平面上找\(n\)个点,要求这 \(n\)个点离原点的距离分别为 \(r1,r2,...,rn\) .最大化这\(n\) 个点构成的凸包面积,凸 ...

随机推荐

  1. Dynamics 365-为什么CRM环境Workflow执行了多次?

    Workflow执行了多次,这个现象如果排除业务逻辑冲突,人为失误等原因,可能有的人遇到的并不多,但是笔者时不时还能遇到这种情况,所以在这里做个记录,也给遇到相同问题的人一个解决的方法. 当一个Wor ...

  2. vue实现表计监测界面

    已经好几个月没有更新博客了,因为最近太忙,忙得连写博客的时间都没有.上班赶项目开启996模式,下班要去练车考驾照,一边还在赶书稿,一边还接了私活.不由得感叹:年纪大了,再也经不起那么折腾..... 每 ...

  3. MongoDB:数据库介绍与基础操作

    二.部署在本地服务器 在上次的学习过程中,我们主要进行了MongoDB运行环境的搭建和可视化工具的安装.此次我们将学习MongoDB有关的基本概念和在adminmongo上的基本操作.该文档中的数据库 ...

  4. 容器化系列 - 通过Grafana监测InfluxDB数据 on Docker

    本文演示在Docker中运行Grafana和InfluxDB,并通过Grafana展示InfluxDB曲线图. 1 准备工作 1.1 安装Docker 请参考这里 1.2 下载镜像 $ docker ...

  5. input输入限制,只允许输入数字和“.”,长度不得超过20

    <input style="margin-top: 10px;width: 100%;text-align:center;" id="removeArea" ...

  6. 搭建一个dubbo+zookeeper平台

    本篇主要是来分享从头开始搭建一个dubbo+zookeeper平台的过程,其中会简要介绍下dubbo服务的作用. 首先,看下一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越多之后 ...

  7. 使用Linq的泛型功能

    泛型数据访问类: 业务抽象类使用数据访问类: 业务类继承业务抽象类: 使用业务类:

  8. BCP SQL导出EXCEL常见问题及解决方法;数据导出存储过程

    一.‘xp_cmdshell’的启用 SQL Server阻止了对组件‘xp_cmdshell’的过程‘sys.xp_cmdshell’的访问.因为此组件已作为此服务嚣安全配置的一部分而被关 闭.系统 ...

  9. c/c++ 重载运算符 函数调用运算符

    重载运算符 函数调用运算符 把一个类的对象a,当成函数来使用,比如a(),所以需要重载operator()方法.重载了函数调用运算符的类的对象,就是函数对象了. 还有什么是函数对象呢??? lambd ...

  10. AFNetworking源码浅析

    本文将从最简单的GET请求方法的使用入手,由表及里,逐步探究AFNetworking如何封装处理原生的网络请求. 一.AFNetworking的简单使用 -(void)getDemo{ AFHTTPS ...