题目描述

  在平面上找 \(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专家罗勇 ,回复287或者20181128可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me ...

  2. C#从SqlServer数据库读写文件源码

    如下的资料是关于C#从SqlServer数据库读写文件的内容,希望能对码农们有一些用. <%@ Page Language="C#" %> <script run ...

  3. Visual Studio 无法记忆标签页、断点等的解决办法

    1.到工程目录删除*.suo文件 2.*.suo默认是隐藏的,需要打开查看隐藏文件的开关

  4. gitbook 入门教程之插件介绍

    插件是 gitbook 的扩展功能,很多炫酷有用的功能都是通过插件完成的,其中插件有官方插件和第三方插件之分. 推荐官方插件市场 https://plugins.gitbook.com/ 寻找或下载相 ...

  5. Python第六天 类型转换

    Python第六天   类型转换 目录 Pycharm使用技巧(转载) Python第一天  安装  shell  文件 Python第二天  变量  运算符与表达式  input()与raw_inp ...

  6. restful api与传统api的区别(方式及语法)

    示例:一个状态数据操作接口 传统模式: api/getstate.aspx- 获取状态信息api/updatestate.aspx - 更新状态信息api/deletestate.aspx - 删除该 ...

  7. C#与SQL Server数据库连接

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. c/c++ 多线程 thread_local 类型

    多线程 thread_local 类型 thread_local变量是C++ 11新引入的一种存储类型. thread_local关键字修饰的变量具有线程周期(thread duration), 这些 ...

  9. Python面试笔记一

    目录 一.MySQL(30题) 二.django(15题) 三.Python部分(46题) 四.RESTful API设计指南(7题) 五.补充 一.MySQL(30题) 1.mysql如何做分页 m ...

  10. idea怎么配置spring

    前提基础: 1.idea软件并JDK成功能用 2.有tacate,并会导入. 3.了解jsp和mvc基本结构 详细介绍: https://www.cnblogs.com/wormday/p/84356 ...