首页 技术 正文
技术 2022年11月15日
0 收藏 749 点赞 3,022 浏览 1016 个字

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1597

就是斜率优化水题…

然而WA了十几遍,正负号处理真让人心累…

还是该负就负,别乱换了…

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int const maxn=;
int n,cnt,q[maxn],h,t;
ll f[maxn],x[maxn],y[maxn];
struct N{ll a,b;}p[maxn];
ll rd()
{
ll ret=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return ret*f;
}
//bool cmp(N x,N y){return x.a==y.a?x.b>y.b:x.a<y.a;}
bool cmp(N x,N y){return x.a==y.a?x.b>y.b:x.a<y.a;}
double slp(int a,int b){return (double)(f[b]-f[a])/(double)(y[a+]-y[b+]);}
int main()
{
n=rd();
for(int i=;i<=n;i++)p[i].a=rd(),p[i].b=rd();
sort(p+,p+n+,cmp);
for(int i=;i<=n;i++)
{
// if(p[i].a==p[i-1].a)continue;
// x[++cnt]=p[i].a; y[cnt]=p[i].b;
while (cnt && p[i].b>=y[cnt]) cnt--;
x[++cnt]=p[i].a; y[cnt]=p[i].b;
}
// h=1;t=1;//
for(int i=;i<=cnt;i++)
{
while(h<t&&slp(q[h],q[h+])<x[i])h++;//<
f[i]=f[q[h]]+x[i]*y[q[h]+];
while(h<t&&slp(q[t-],q[t])>slp(q[t],i))t--;
q[++t]=i;
}
printf("%lld",f[cnt]);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,022
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,773
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,851