BZOJ 1588: [HNOI2002]营业额统计 双向链表
BZOJ 1588: [HNOI2002]营业额统计
Time Limit: 5 Sec Memory Limit: 512 MB
Submit: 9619 Solved: 3287
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=1588
Description
Input
Output
Sample Input
5
1
2
5
4
6
Sample Output
HINT
结果说明:5+|1-5|+|2-1|+|5-5|+|4-5|+|6-5|=5+4+1+0+1+1=12
此题数据有问题,详见讨论版http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=1588
题解:
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 400001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//************************************************************************************** struct node
{
int p,v,left,right;
}a[maxn]; int n,ra[maxn];
inline bool cmp(node a,node b)
{
return a.v<b.v;
}
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i].v;
a[i].p=i;
}
sort(a+,a+n+,cmp);
for(int i=;i<=n;i++)
{
ra[a[i].p]=i;
a[i].left=i-;
a[i].right=i+;
}
a[n].right=;
int ans=a[ra[]].v;
for(int i=n;i>;i--)
{ int x=ra[i];
if(a[x].left!=&&a[x].right!=)
{ ans+=min(a[x].v-a[a[x].left].v,a[a[x].right].v-a[x].v);
a[a[x].left].right=a[x].right;
a[a[x].right].left=a[x].left;
}
else if(a[x].left==)
{ ans+=a[a[x].right].v-a[x].v;
a[a[x].right].left=;
}
else
{
ans+=a[x].v-a[a[x].left].v;
a[a[x].left].right=;
} }
cout<<ans<<endl;
return ;
}
BZOJ 1588: [HNOI2002]营业额统计 双向链表的更多相关文章
- BZOJ 1588: [HNOI2002]营业额统计 双向链表 / splay / treap
1588: [HNOI2002]营业额统计 Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger ...
- BZOJ 1588: [HNOI2002]营业额统计
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 14396 Solved: 5521[Submit][Sta ...
- bzoj 1588: [HNOI2002]营业额统计 treap
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 13902 Solved: 5225[Submit][Sta ...
- 数据结构:(平衡树,链表)BZOJ 1588[HNOI2002]营业额统计
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 12173 Solved: 4354[Submit][Sta ...
- 2018.07.06 BZOJ 1588: HNOI2002营业额统计(非旋treap)
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MB Description 营业额统计 Tiger最近被公司升任为营业部经理,他上 ...
- Bzoj 1588: [HNOI2002]营业额统计(splay)
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MB Description 营业额统计 Tiger最近被公司升任为营业部经理,他上 ...
- SET || BZOJ 1588: [HNOI2002]营业额统计 || Luogu P2234 [HNOI2002]营业额统计
题面:P2234 [HNOI2002]营业额统计 题解:随便写写 注意:cmath中abs函数返回的是一个浮点数,在bzoj上会ce 代码: #include<cstdio> #inclu ...
- BZOJ 1588 [HNOI2002]营业额统计(双向链表)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1588 [题目大意] 给出一个数列,对于每个数,选择其前面的某个数作差取绝对值, 使得所 ...
- bzoj 1588 [HNOI2002] 营业额统计 链表和Splay
来自HNOI 2002营业额的统计一题,这题以前是用链表水过的,最近看见许多splay的题,赶紧张一下知识. 题目大意就是对于一个序列,输出每个元素与它之前元素的差的最小值的和.先说链表的方法吧. 大 ...
随机推荐
- swagger学习
https://segmentfault.com/a/1190000010144742 https://segmentfault.com/a/1190000014775124 https://blog ...
- c# List 所有操作方法例子
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Ref ...
- CKEDITOR的内容js转码,C#控制器解码接收
<script type="text/javascript" src="<%=Url.Content("~/Resource/ckeditor/ck ...
- Vue 进阶教程之:详解 v-model
分享 Vue 官网教程上关于 v-model 的讲解不是十分的详细,写这篇文章的目的就是详细的剖析一下, 并介绍 Vue 2.2 v-model改进的地方,然后穿插的再说点 Vue 的小知识. 在 V ...
- Python开发环境(2):启动Eclipse时检测到PYTHONPATH发生改变
OS:Windows 10家庭中文版,Eclipse:Oxygen.1a Release (4.7.1a),PyDev:6.3.2 4月25日,在Eclipse上安装了PyDev(前面博文有记录),并 ...
- 移动端Touch事件
案例1: <!doctype html> <html lang="en"> <head> <meta charset="UTF- ...
- js中的盒子模型
说到盒子模型,你第一时间会想到css盒子模型,css中的盒子模型包括(内容区+内边距+边框).那在js中怎么去获取这些属性值呢?下面一起来学习js中的盒子模型. css样式 body { margin ...
- iframe框架加载完成后执行函数
var iframe = document.createElement("iframe"); iframe.src = "http://www.baidu.com/&qu ...
- AdvStringGrid 点击标题头 自动排序
- CxGrid 表格标题头居中
选中这些列后 搞.