【BZOJ 1588】 [HNOI2002]营业额统计
2024-10-01 14:39:30
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
每天的最小波动值指的是和之前所有天的差值的绝对值中的最小值。
用set.的lower_bound函数。
每次找和他差值最小的数字就好。
(不要用lower_bound(myset.begin(),myset.end(),x)
这个比较慢
而应该用myset.lower_bound(x)
就能ac了
【代码】
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;
int n;
long long ans = 0;
set<int> myset;
int main(){
//freopen("D:\\rush.txt","r",stdin);
scanf("%d",&n);
for (int i = 1;i <= n;i++){
int x;
scanf("%d",&x);
if (i==1) ans = x;else{
int temp = -1;
set<int>::iterator pos = myset.lower_bound(x);
int temp1 = (*pos);
temp1 = abs(temp1-x);
if (pos!=myset.end()) temp = temp1;
if (pos!=myset.begin()){
pos--;
temp1 = (*pos);
temp1 = abs(temp1-x);
if (temp==-1)
temp = temp1;
else
temp = min(temp1,temp);
}
ans+=temp;
}
myset.insert(x);
}
printf("%lld\n",ans);
return 0;
}
最新文章
- vscode常用设置
- CentOS下安装hadoop
- JAVA开发相关
- 关于Xcode7中添加不了libresolv.dylib等类似库的问题
- Spring之LoadTimeWeaver——一个需求引发的思考---转
- 关于iOS去除数组中重复数据的几种方法
- Intent详解
- 转:MIME(Multipurpose Internet Mail Extensions)类型
- Linux内核学习方法
- parsing html in asp.net
- Linux就是这个范儿之第一次亲密接触(3)
- php多线程即时通讯
- Java的虚方法
- PM意识升级2.0
- keras 入门整理 如何shuffle,如何使用fit_generator 整理合集
- await异步的,容易理解一点
- 搭建django
- centos7环境下开启指定端口
- Cassandra创建第一个用户
- javascript获取id元素
热门文章
- Docker-镜像的操作命令
- redis 篇 - hash
- [terry笔记]python购物程序
- java中的hachcode方法
- [ReactVR] Animate Text, Images, Views, and 3D Elements Using the Animated Library in React VR
- 【MongoDB】深入了解MongoDB不可不知的十点
- 无法连接虚拟设备 ide1:0,因为主机上没有相应的设备。您要在每次开启此虚拟机时都尝试连接此虚拟设备吗?
- WIN32常用
- FastJSON杂项
- KafkaZookeeper2-ZookeeperClient