优先队列。

做法:维护两个优先队列:quesell  和  quebuy, 一个是小值优先,一个是大值优先。每次push的时候,都取各自的Top元素,比较价格,如果卖的比卖的出价低,则成交,各自的要买和要卖的股票数量减少能够减少的最大值,此时的DP(DealPrice)被记录下来。

具体见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
#define N 100003 struct SELL
{
int price,num;
bool operator <(const SELL &a)const
{
return price>a.price;
}
}; struct BUY
{
int price,num;
bool operator <(const BUY &a)const
{
return price<a.price;
}
}; int main()
{
int t,n,i;
char ss[],share[],at[];
int num,price;
SELL ka;
BUY kb;
scanf("%d",&t);
int DP;
while(t--)
{
priority_queue<SELL> quesell;
priority_queue<BUY> quebuy;
DP = -;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%s%d%s%s%d",ss,&num,share,at,&price);
if(ss[] == 'b')
{
kb.price = price;
kb.num = num;
quebuy.push(kb);
}
else
{
ka.price = price;
ka.num = num;
quesell.push(ka);
}
int minnum;
if(!quesell.empty() && !quebuy.empty())
{
while()
{
if(quesell.empty() || quebuy.empty())
break;
BUY li = quebuy.top();
SELL wi = quesell.top();
if(wi.price <= li.price)
{
quebuy.pop();
quesell.pop();
if(wi.num > li.num)
{
wi.num -= li.num;
quesell.push(wi);
}
else if(wi.num < li.num)
{
li.num -= wi.num;
quebuy.push(li);
}
DP = wi.price;
}
else
break;
}
if(!quesell.empty())
printf("%d ",quesell.top().price);
else
printf("- ");
if(!quebuy.empty())
printf("%d ",quebuy.top().price);
else
printf("- ");
if(DP == -)
printf("-\n");
else
printf("%d\n",DP);
}
else
{
if(!quesell.empty())
printf("%d ",quesell.top().price);
else
printf("- ");
if(!quebuy.empty())
printf("%d ",quebuy.top().price);
else
printf("- ");
if(DP == -)
printf("-\n");
else
printf("%d\n",DP);
}
}
}
return ;
}

UVA 12266 Stock prices --优先队列的更多相关文章

  1. hdu 4163 Stock Prices 水

    #include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #de ...

  2. hdu 4163 Stock Prices 花式排序

    Stock Prices Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. UVA.136 Ugly Numbers (优先队列)

    UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...

  4. uva 1422 - Processor(二分+优先队列)

    题目链接:uva 1422 - Processor 题目大意:有一个机器要处理一些问题,给出这些问题可以开始的时间和必须完成的时间,以及任务的工作量,问说机器必须以最少每秒多少得工作量才能完成这些任务 ...

  5. UVa 11134 - Fabled Rooks 优先队列,贪心 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  6. UVa 10954 Add All(优先队列)

    题意  求把全部数加起来的最小代价  a+b的代价为(a+b) 越先运算的数  要被加的次数越多  所以每次相加的两个数都应该是剩下序列中最小的数  然后结果要放到序列中  也就是优先队列了 #inc ...

  7. uva 10537 Toll! Revisited(优先队列优化dijstra及变形)

    Toll! Revisited 大致题意:有两种节点,一种是大写字母,一种是小写字母. 首先输入m条边.当经过小写字母时须要付一单位的过路费.当经过大写字母时,要付当前財务的1/20做过路费. 问在起 ...

  8. 【暑假】[深入动态规划]UVa 1412 Fund Management

    UVa 1412 Fund Management 题目: UVA - 1412 Fund Management Time Limit: 3000MS   Memory Limit: Unknown   ...

  9. 第3.2 使用案例1:股票期货stock portfolio 21050917

    As mentioned earlier in the chapter, the first use case revolves around a stock portfolio use case  ...

随机推荐

  1. mybatis中自建的类型别名

    在使用mybatis过程中经常用到类型别名,除了我们自己新建的别名外,mybatis还自带了很多类型别名和java中的类型的映射,下面先看一个自建的别名的配置 <typeAliases> ...

  2. Oracle自动统计信息的收集原理及实验

    [日期:2014-11-21]来源:Linux社区  作者:stevendbaguo[字体:大 中 小] 从Oracle Database 10g开始,Oracle在建库后就默认创建了一个名为GATH ...

  3. 在 SharePoint Server 2013 中配置建议和使用率事件类型

    http://technet.microsoft.com/zh-cn/library/jj715889.aspx 适用于: SharePoint Server 2013 利用使用事件,您可以跟踪用户与 ...

  4. SeismicPro地震剖面显示程序

    SeismicPro是一个地震剖面显示软件,可从标准SEGY地震数据体中抽取纵测线和横测线的二维剖面,并以波形.变面积和变密度等多种方式进行专业化显示,可进行一键式显示方式切换,并可进行定制开发叠加井 ...

  5. Android 6.0权限管理

    Android 6.0权限管理 关于权限管理 Android6.0 发布之后,Android 的权限系统被重新设计.在 23 之前 App 的权限只会在用户安装的时候询问一次,App一旦安装后就可以使 ...

  6. UIWebView的简单使用

    在iOS9.0之后需要在ifo.plist文件中添加一个配置文件,不然只能识别https开头的网址,http开头的不识别 主要有三个步骤 // 1.获取URL NSURL *url = [NSURL ...

  7. Android学习一(入门)

    一.Android 系统简介 1.1.1G-4G 1G:模拟制式手机,1995年问世的第一代模拟制式手机,只能进行语音通话, 2G:手机使用GSM,CDMA(9K/s),增加了接收数据的功能 2.5G ...

  8. JAVA基础学习day23--GUI基础

    一.GUI概述 1.1.GUI概述 Graphical User Interface(图形用户接口) 用图形的方式,来显示计算机操作的界面, CLI: Command line User Interf ...

  9. IOS 网络浅析-(六 网络图片获取之三方SDWebImage)

    网络图片获取是大多数app所能用到的,由于实际app开发中原生api很少用到,在这里就先不介绍了,以后有时间会给大家介绍.这篇文章会给大家介绍一个三方-SDWebImage.SDWebImage 是一 ...

  10. 招聘一个靠谱的 iOS程序员

    一个靠谱的简历 简历非常能反映一个人的性格和水平,相比于你在学校获得多少奖项,工作经历.项目经 历.熟悉的技术等更加关键,如果还有博客和一些 Github 上的项目,好感度++,但记得在去面试前收拾下 ...