bzoj 1588 bst
2024-09-26 09:13:31
用set存下就好了。
/**************************************************************
Problem: 1588
User: BLADEVIL
Language: C++
Result: Accepted
Time:180 ms
Memory:1468 kb
****************************************************************/ //By BLADEVIL
#include <cstdio>
#include <set>
#define inf 1<<30 using namespace std; int n,ans; int main()
{
int x;
set<int>bt;
bt.insert(inf); bt.insert(-inf);
scanf("%d",&n);
for (int i=;i<=n;i++)
{
//printf(" %d\n",ans);
if (scanf("%d",&x)==EOF) x=;
if (i==) ans=x,bt.insert(x); else
{
int a,b;
a=*bt.upper_bound(x); b=*(--bt.upper_bound(x));
ans+=(a-x<x-b)?a-x:x-b;
bt.insert(x);
}
}
printf("%d\n",ans);
return ;
}
最新文章
- [LeetCode] Ugly Number II 丑陋数之二
- java归并排序,单线程vs多线程
- Objective—C基础学习总结
- CSS3 选择器——伪类选择器
- Some settings of PostgreSQL
- EasyUI-在iframe里获取现阶段选中的tab的标题
- oc-04-类的声明和实现
- PHP验证码的制作
- Project Euler:Problem 55 Lychrel numbers
- linux下virtualenv的python版本
- CF# 260 A. Laptops
- Linux删除其他程序正在使用的文件
- mshadow的原理--MXNet
- pandas,pd.ExcelWriter保存结果到已存在的excel文件中
- 「POJ - 1003」Hangover
- Backbone 学习总结
- Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点( FROM IBM)
- 数据加密之RijndaelManaged加密
- SQL Server T—SQL 语句【建 增 删 改】(建外键)
- mfc Unicode转 ASNI ,WCHAR 转 CHAR
热门文章
- 原生javascript自定义input[type=radio]效果
- WITH REPLACE 含义
- WriteLine(ls.ToString());Console.WriteLine(ls);输出结果相同,为什么要加 .ToString()
- window service 创建
- javascript中检测一个变量的类型
- Socket_SSH-2(大文件的一次传输)
- JS详细图解全方位解读this
- A表数据插入到B表(表结构不一致)
- 「CodePlus 2017 12 月赛」白金元首与独舞
- Spring boot——构建rest风格