BZOJ 3203 sdoi 2013 保护出题人
2024-08-25 20:42:31
由于样例解释很清晰,所以很容易得到以下结论:
1、每一关都是独立的,且僵尸的相对位置不会变
2、每一关的攻击力=Max(sum(i)/dis(i))
其实sum(i)是僵尸攻击力的前缀和,dis(i)是距离
然后因为输入是每次在队头添加,所以我们可以把前缀和转换成后缀和
攻击力=Max( (sum_i-sum_j)/(x_i+i*d-j*d) )
这显然是一个斜率的式子,又因为僵尸的相对位置不变
所以我们可以维护一个下凸壳,之后每次在凸壳上三分最优解即可
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#define eps 1e-8
using namespace std; const int maxn=100010;
int n,top=0,cur;
double d,ans;
double A[maxn],X[maxn];
double sum[maxn];
struct Point{
double x,y;
Point(double x=0,double y=0):x(x),y(y){}
};
Point st[maxn];
typedef Point Vector;
Vector operator -(const Point &A,const Point &B){return Vector(A.x-B.x,A.y-B.y);}
double Cross(const Point &A,const Point &B){return A.x*B.y-A.y*B.x;} double F(int x){
return (sum[cur]-st[x].y)/(X[cur]+cur*d-st[x].x);
} int main(){
scanf("%d%lf",&n,&d);
for(int i=1;i<=n;++i)scanf("%lf%lf",&A[i],&X[i]),sum[i]=sum[i-1]+A[i];
for(int i=1;i<=n;++i){
Point now=Point(d*i,sum[i-1]);
while(top>=2&&Cross(now-st[top],st[top]-st[top-1])>eps)top--;
st[++top]=now;cur=i;
int L=1,R=top;
while(R-L>=3){
int m1=(L+L+R)/3,m2=(L+R+R)/3;
if(F(m1)>F(m2))R=m2;
else L=m1;
}
double sum=-1e18;
for(int j=L;j<=R;++j)sum=max(sum,F(j));
ans+=sum;
//printf("%.8lf\n",sum);
}printf("%.0lf\n",ans);
return 0;
}
最新文章
- C#操作图片帮助类
- ASP.NET MVC5 网站开发实践(二) Member区域 - 用户部分(1)用户注册
- UTC与GMT时间
- python 异常
- 面试复习(C++)之冒泡排序
- Pip install lxml centOSFailed building wheel for lxml
- asp.net 使用UrlRewritingNet.UrlRewriter组件URL重写,伪静态详解
- jQuery get post 碎片(远程html)加载
- What is the difference between DAO and DAL?
- 深刻理解C#中资源释放
- <;有序数组>;转化为<;按二分法遍历顺序排列的数组>;(C++实现)
- 【JSP动态网站】JDBC连接SqlServer 2008数据库
- ASP.NET Web API的HttpController是如何被激活的?
- HTTP相关整理(上)
- nginx隐藏tp路由index.php
- 批处理脚本+adb命令
- NSURLConnectionDataDelegate
- Eclipse的设置、调优、使用(解决启动卡顿等问题)----转
- 解决默写浏览器中点击input输入框时,placeholder的值不消失的方法
- Windows程序
热门文章
- android-support-xxxx.jar NoClassDefFoundError
- MQTT开发小记(一)
- Silverlight动画学习笔记(三):缓动函数
- c++ 进程权限的提升
- google查询技巧
- 系统中使用frameset和Iframe刷新页面session失效
- Elastix 禁用SSL(https),还原为 http 访问
- [转]init.d解析
- selenium+python 浏览器标签页跳转 switch_to_window
- gif修改背景透明