博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces # 317 div 2 B. Order Book(模拟)
阅读量:4624 次
发布时间:2019-06-09

本文共 4267 字,大约阅读时间需要 14 分钟。

B. Order Book
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In this task you need to process a set of stock exchange orders and use them to create order book.

An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or sell, and integer qi. This means that the participant is ready to buy or sell qi stocks at price pi for one stock. A value qi is also known as a volume of an order.

All orders with the same price p and direction d are merged into one aggregated order with price p and direction d. The volume of such order is a sum of volumes of the initial orders.

An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order.

An order book of depth s contains s best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than s aggregated orders for some direction then all of them will be in the final order book.

You are given n stock exhange orders. Your task is to print order book of depth s for these orders.

Input

The input starts with two positive integers n and s (1 ≤ n ≤ 1000, 1 ≤ s ≤ 50), the number of orders and the book depth.

Next n lines contains a letter di (either 'B' or 'S'), an integer pi (0 ≤ pi ≤ 105) and an integer qi (1 ≤ qi ≤ 104) — direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order.

Output

Print no more than 2s lines with aggregated orders from order book of depth s. The output format for orders should be the same as in input.

Sample test(s)
input
6 2 B 10 3 S 50 2 S 40 1 S 50 6 B 20 4 B 25 10
output
S 50 8 S 40 1 B 25 10 B 20 4
Note

Denote (x, y) an order with price x and volume y. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.

You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.

 

昨天头疼。。然后觉得要掉。。就用小号打的。。。

结果涨了200+rating。。。。

这题就是纯模拟啊。。。

一遍ac。。。

需要注意的地方,如果说有。。。

大概就是,sell的是取最小的s个,要先从小到大排序。。。但是输出的时候又是从大到小排序。。。

昨天40分钟做完前2道题。。然后c题不会搞。。。就水群(求不鄙视> <),好像一堆人wa b wa得特别惨的样子。。。

1 /*************************************************************************  2     > File Name: code/cf/#317/B.cpp  3     > Author: 111qqz  4     > Email: rkz2013@126.com   5     > Created Time: 2015年08月23日 星期日 00时30分51秒  6  ************************************************************************/  7   8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 #include
21 #define y1 hust111qqz 22 #define yn hez111qqz 23 #define j1 cute111qqz 24 #define ms(a,x) memset(a,x,sizeof(a)) 25 #define lr dying111qqz 26 using namespace std; 27 #define For(i, n) for (int i=0;i
b.val) return true; 51 return false; 52 } 53 int main() 54 { 55 #ifndef ONLINE_JUDGE 56 freopen("in.txt","r",stdin); 57 #endif 58 cin>>n>>ss; 59 int x,y; 60 char order; 61 ms(b,0); 62 ms(s,0); 63 ms(id,0); 64 ms(id2,0); 65 int cntA=0,cntB= 0 ; 66 for ( int i = 0 ; i < n ; i++){ 67 cin>>order>>x>>y; 68 if (order=='B'){ 69 if (id[x]==0) 70 { 71 cntA++; 72 id[x] = cntA; 73 } 74 b[id[x]].num = b[id[x]].num + y; 75 b[id[x]].val = x; 76 b[id[x]].id = id[x]; 77 } 78 else 79 { 80 if (id2[x]==0) 81 { 82 cntB++; 83 id2[x] = cntB; 84 } 85 s[id2[x]].num = s[id2[x]].num+y; 86 s[id2[x]].val = x; 87 s[id2[x]].id = id2[x]; 88 } 89 } 90 sort(s+1,s+cntB+1,cmp); 91 sort(b+1,b+cntA+1,cmp2); 92 cntA = min(cntA,ss); 93 cntB = min(cntB,ss); 94 ms(ans,0); 95 for ( int i = 1 ; i <= cntB ; i++){ 96 ans [i].val = s[i].val; 97 ans[i].num = s[i].num; 98 } 99 sort(ans+1,ans+cntB+1,cmp2);100 for ( int i = 1; i <= cntB ; i++){101 cout<<"S "<
<<" "<
<
View Code

 

转载于:https://www.cnblogs.com/111qqz/p/4752675.html

你可能感兴趣的文章
MySQL体系结构
查看>>
Nginx-日志切割
查看>>
219. Insert Node in Sorted Linked List【Naive】
查看>>
CentOS下安装mysql及配置使用
查看>>
Sublime Text3配置Vue 语法
查看>>
验证控件:RegularExpressionValidator
查看>>
hdu1166 线段树单点修改与区间查询
查看>>
asp.net -mvc框架复习(7)-基于MVC搭建用户登录项目框架
查看>>
CSS background-clip 属性
查看>>
python中函数作用域
查看>>
C#版清晰易懂TCP通信原理解析(附demo)
查看>>
系统自带的粒子系统
查看>>
Laravel 框架的主要版本
查看>>
pandas学习笔记 - 常见的数据处理方式
查看>>
云监控中的告警
查看>>
大题的简单解答
查看>>
CSS3复选框动画
查看>>
Base64.java 工具类
查看>>
ExtJS遮罩层Ext.loadMask
查看>>
ArcPy开发教程2-管理地图文档1
查看>>