题目描述

  在平面上找 \(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. Chrome opacity非1时border-radius圆角边框剪裁问题

    border-radius:50%可以让元素正方形元素表现为正圆. 如果元素设置了border边框,则会表现为一个正圆圈圈,类似这样: 但有时候,border边框的这个圈圈会在边缘处发生剪裁,个别浏览 ...

  2. PHP技能树

  3. Android为TV端助力(转载)

    作者地址http://www.jianshu.com/u/63915ef020e2 针对Android Tv的自定义RecyclerView 作者 wenju_song 关注 2016.12.09 1 ...

  4. mssql sqlserver 表增加列后,视图不会自动更新相关列的两种解决方法分享

    摘要: 今天对物理数据表,进行增加列操作后,程序一直显示无法找到相应列,通过仔细比对发现,视图中无相应列更新,下文将具体的解决方法分享如下: 例: create view vw_test as sel ...

  5. .net向文件写入字符串流内存溢出的问题

    字符串过大导致抛出异常: exceptopm of type 'system.outOfmemoryexception' was thrown 解决方法:逐块写入可以避免这个问题

  6. 在Centos7.2(64位)下搭建Web服务器

    一:通过Yum安装mysql 1 # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm 2 # rpm -i ...

  7. 为什么不建议在 HBase 中使用过多的列族

    我们知道,一张 HBase 表包含一个或多个列族.HBase 的官方文档中关于 HBase 表的列族的个数有两处描述: A typical schema has between 1 and 3 col ...

  8. VS 附加到进程 加载“附加进程”弹窗很慢

    最近遇到一个问题,点击Ctrl + Alt + P 附加到进程的时候,弹出下图弹窗“附加到进程”很慢. 找了很多原因,后来发现,是因为少安装了一个插件,安装后,弹窗的耗时明显少了. 下载    Win ...

  9. 在windows下远程访问linux桌面

    一.安装xrdp工具: #  yum install xrdp #   yum install tigervnc-server #   service xrdp start 以上三个命令执行完毕安装完 ...

  10. F. Multicolored Markers(数学思维)

    思维:思维就是将大的矩形放在小矩形里面,让大矩形的宽和长尽量靠近. 很容易得到 (a+b)% i = 0 的话, 保证了大矩形的形成,同时里面表示了两种情况:1, a % i =0, b % i=0; ...