强烈谴责$skyh$的没$\Huge 脸$行为。

很经典的可反悔贪心,然而我一直以为是sbdp还一直想着怎么优化……

正常的贪心肯定是不对的。

但是由于A-C=A-B+B-C,

所以用一个小根堆维护,每次将当前天的a加入,表示当前天可以买入,

如果堆顶小于a,取出堆顶,ans加上差,再次将当天的a加入,那么如果之后卖出更优则会减掉当前的a利用差价满足了贪心性质。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define int LL
#define LL long long
using namespace std;
int n,a[]; inline int read();
signed main()//dp xds//优化dp//单调
{
// freopen("trade14.in","r",stdin); n=read();for(int i=;i<=n;i++)a[i]=read(); priority_queue<int,vector<int>,greater<int> >A;
LL ans=;A.push(a[]);
for(int i=;i<=n;i++)
{
if(A.top()<a[i])
{
ans+=a[i]-A.top();A.pop();
A.push(a[i]);
}
A.push(a[i]);
}
printf("%lld\n",ans);
}
inline int read()
{
int s=,f=;char a=getchar();
while(a<''||a>''){if(a=='-')f=-;a=getchar();}
while(a>=''&&a<=''){s=s*+a-'';a=getchar();}
return s*f;
}

HZOJ trade的更多相关文章

  1. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. Hdu 1009 FatMouse' Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. [题解]hdu 1009 FatMouse' Trade(贪心基础题)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  4. ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)

    题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...

  5. HDU 3401 Trade dp+单调队列优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others)Mem ...

  6. 【HDU 1009】FatMouse' Trade

    题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...

  7. hdu 1009:FatMouse' Trade(贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. 杭电1009-FatMouse' Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. LC327 Count of Range Number

    这一题,我们使用了分治法. 首先看时间复杂度为o(n^2),比较naïve的方法: 使用一个数组sum[],长度为原数组长度+1,每一个元素sum[i]为原数组中index0~i-1之和,显然当sum ...

  2. CF 549B Looksery Party

    题面 解题思路 如果a数组全部>0,那么都不去即可.从这个角度出发,每次选出a[i]为0的,让它们去更新a数组,相当于拓补排序. 代码 #include<iostream> #inc ...

  3. TZ_16_Vue父子组件之间的通信

    1.父向子传递props,该如何传递 <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  4. 【arc077f】AtCoder Regular Contest 074 F - Lotus Leaves

    题意 给定一个n*m的池塘,每个格子上可能有叶子. 从一个叶子出发,可以跳到相同行或相同列的叶子. 问至少去掉多少叶子,使得起点不能到达终点. \(n,m<=100\) 解法 很显然的最小割模型 ...

  5. jnhs-SpringMVC的controller向jsp传递数据的五种方式

    参考此文http://blog.sina.com.cn/s/blog_6d3c1ec601014h1h.html 1 使用ModelAndVoew 引入:org.springframework.web ...

  6. 基于python爬虫的github-exploitdb漏洞库监控与下载

    基于python爬虫的github-exploitdb漏洞库监控与下载 offensive.py(爬取项目历史更新内容) #!/usr/bin/env python # -*- coding:utf- ...

  7. 洛谷P1774 最接近神的人_NOI导刊2010提高(02) [2017年6月计划 线段树03]

    P1774 最接近神的人_NOI导刊2010提高(02) 题目描述 破解了符文之语,小FF开启了通往地下的道路.当他走到最底层时,发现正前方有一扇巨石门,门上雕刻着一幅古代人进行某种活动的图案.而石门 ...

  8. CenOS SSH无密码登录

    系统环境:CentOS6.8 软件环境:SSH(yum -y install openssh-clients) IP   地址:192.168.0.188 用户环境:root.xiaoming  系统 ...

  9. 模拟20 题解(waiting)

    留坑待填 T2 #include<cstdio> #include<vector> #include<cstring> #include<iostream&g ...

  10. QT_获取正在运行程序的进程id(判断程序是否正在运行)

    bool checkProcessRunning(const QString &processName, QList<quint64> &listProcessId) { ...