http://www.lydsy.com/JudgeOnline/problem.php?id=1588

直接set做就好了,注意set的迭代器只能--之类的操作。

OJ崩了,也不知道对错。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std; set<int> s;
set<int>::iterator it; int main()
{
int temp,n;
scanf("%d",&n);
scanf("%d",&temp);
int sum = temp;
s.insert(temp);
for(int i = ;i <= n;i++)
{
scanf("%d",&temp);
it = s.lower_bound(temp);
if(it == s.begin()) sum += *it-temp;
else if(it == s.end()) sum += temp-*(--it);
else
{
int a = *it-temp,b = temp-*(--it);
sum += min(a,b);
}
s.insert(temp);
}
printf("%d\n",sum);
return ;
}

HYSBZ_1588_set的更多相关文章

随机推荐

  1. 27.python中excel处理库openpyxl使用详解

    openpyxl是一个第三方库,可以处理xlsx格式的Excel文件.pip install openpyxl安装. 读取Excel文件 需要导入相关函数 ? 1 2 3 from openpyxl ...

  2. 关于Springboot找不到mapper.xml问题

    今天在写springboot项目时报错org.apache.ibatis.binding.BindingException: Invalid bound statement (not found),找 ...

  3. Redhat6 RPM 软件管理常用命令汇总

    软件的安装时操作系统管理的基础,与Windows不同,Linux的软件管理有很多种方式,Redhat的最常用的是RPM方式,安装集成在光盘中的RPM包.这种方式比Windows平台的软件管理更加便捷( ...

  4. VUE CLI环境搭建文档

    VUE CLI环境搭建文档 1.安装Node.js 下载地址 https://nodejs.org/zh-cn/download/ 2.全局安装VUE CLI win+R键打开运行cmd窗口输入一下代 ...

  5. python修改列表

    替换元素 效果图: 代码: #创建一个列表 list = ['a','b','c','d','e','f'] print('修改前:',list) #修改元素 指定索引重设其值 list[1] = ' ...

  6. vue超简单加载字体方法,解决scss难加载字体的问题

    vue超简单加载字体方法,解决scss难加载字体的问题 scss在加载字体方面一直不太好用,需要繁杂的配置才能达到想要的效果,这里说一种非常简单的方法 在App.vue的style标签下引入字体文件后 ...

  7. springcloud复习1

    1.SpringCloud是什么?SpringCloud=分布式微服务架构下的一站式解决方案,是各个微服务架构落地技术的集合体,俗称微服务全家桶. 2.SpringCloud和SpringBoot是什 ...

  8. Python中的open()方法总结

    总结Python中的open()方法 message= {'企业即时通信': 'aaa', '企业名称': 'bbb'} with open("..\\r.txt", " ...

  9. 测试工具Fiddler(二)—— 入门使用

    Fiddler设置与安装证书 一.Fiddler常见设置 Options位置:Tools->Options 二.移动端连上Fiddler作为代理 注意:因为Charles也是默认8888端口,小 ...

  10. 关于爬虫的日常复习(14)—— 爬虫beautifulsoup的初级高级的基本用法