[二分答案 DP检验 几何] BalkanOI 2017. Cruise
来源:互联网 发布:星际争霸2和lol知乎 编辑:程序博客网 时间:2024/06/08 03:15
题意是给定平面内2000给点(都在y轴右边),要选出一些点,和原点组成多边形,求在多边形内的点的点权和除以多边形周长的最大值。
分数规划,二分答案
这样求
发现答案肯定是个凸多边形
考虑DP,把点按照极角排序,令
那么
其中
#include <cstdio>#include <iostream>#include <algorithm>#include <set>#include <cmath>#include <assert.h>using namespace std;const int N=2010;const double eps=1e-8;int n;double f[N];struct Pt{ int x,y,g,w; double val; Pt(int _a=0,int _b=0):x(_a),y(_b){} friend bool operator <(Pt a,Pt b){ return b.val>a.val; } friend Pt operator -(Pt a,Pt b){ return Pt(a.x-b.x,a.y-b.y); } double len(){ return sqrt(x*x+y*y); }}p[N],tmp[N];inline double ang(Pt a,Pt b){ return acos((a.x*b.x+a.y*b.y)/a.len()/b.len());}inline double dist(Pt a,Pt b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int pos[N],b[N],g[N][N];inline int Query(int x,int n){ int ret=0; for(;x<=n;x+=x&-x) ret+=b[x]; return ret;}inline void Add(int x,int y){ for(;x;x-=x&-x) b[x]+=y;}inline bool check(double x){ for(int i=1;i<=n;i++) f[i]=p[i].w-dist(p[i],Pt())*x; for(int i=2;i<=n;i++) for(int j=1;j<i;j++){ f[i]=max(f[i],f[j]+g[j][i]-x*dist(p[i],p[j])); } for(int i=1;i<=n;i++) if(f[i]-x*dist(p[i],Pt())>=0) return true; return false;}inline void Pre(){ for(int i=1;i<=n;i++){ int cnt=0,tot=0; for(int j=i+1;j<=n;j++){ tmp[++cnt]=p[j]; tmp[cnt].val=ang(p[j]-p[i],p[i]); tmp[cnt].g=j; } sort(tmp+1,tmp+1+cnt); for(int j=1;j<=cnt;j++){ pos[tmp[j].g]=j; b[j]=0; } for(int j=i+1;j<=n;j++){ Add(pos[j],p[j].w); g[i][j]=Query(pos[j],cnt); } }}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].w),p[i].val=ang(p[i],Pt(0,-1)); sort(p+1,p+1+n); Pre(); double L=0,R=1e9,mid; while(R-L>eps){ check(mid=(L+R)/2)?L=mid:R=mid; } printf("%.8lf\n",R); return 0;}
阅读全文
0 0
- [二分答案 DP检验 几何] BalkanOI 2017. Cruise
- 计算几何 [二分答案]
- [DP] BalkanOI 2016. Lefkaritika
- 洛谷 P1800 software_NOI导刊2010提高(06)(二分答案+DP检验)
- hdu3586(树形DP+二分答案)
- Topcoder SRM658,DP+二分答案,
- 二分答案加DP判断
- [dp][二分答案]最大正方形
- bzoj4985 评分(二分答案+dp)
- bzoj3993 [SDOI2015]星际战争 二分答案+网络流检验
- bzoj3130 [SDOI2013]费用流 结论+二分答案+网络流检验
- UVALive 4625 Garlands(二分答案 + DP)
- UVALive 3608 Period(二分答案+DP)
- [BZOJ1044]HAOI2008木棍分割|DP|二分答案
- so就 (二分答案 dp 贪心)
- 【HDU3586】Information Disturbing-二分答案+树形DP
- CEOI2017 D1T3 mousetrap 树形dp+二分答案
- 道路覆盖 (二分答案+状压DP)
- $match
- 注解的定义以及获取注解里面的方法,变量
- 洛谷1137 旅行计划
- label statement
- Tarjan求割点
- [二分答案 DP检验 几何] BalkanOI 2017. Cruise
- 系统限制
- js日期格式化
- Sublime Text3自动保存的功能(失去焦点自动保存)
- solr7在tomcat上的部署
- [线段树 哈希] BalkanOI 2016. Haker
- CentOS 6.5 LVS+KeepAlived(DR模式)搭建高可用负载均衡集群
- $project
- 使用PC Tools时在板端执行HiPCTools.sh后报不能加载libstdc++.so.6的错误是怎么回事?