CodeForces
来源:互联网 发布:什么软件可以下载软件 编辑:程序博客网 时间:2024/04/30 20:59
In this task you need to process a set of stock exchange orders and use them to createorder book.
An order is an instruction of some participant to buy or sell stocks on stock exchange. The order numberi has price pi, directiondi — buy or sell, and integerqi. This means that the participant is ready to buy or sellqi stocks at pricepi for one stock. A valueqi is also known as avolume of an order.
All orders with the same price p and directiond are merged into one aggregated order with price p and directiond. 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 thans 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 depths for these orders.
The input starts with two positive integers n ands (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 integerpi (0 ≤ pi ≤ 105) and an integerqi (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.
Print no more than 2s lines with aggregated orders from order book of depths. The output format for orders should be the same as in input.
6 2B 10 3S 50 2S 40 1S 50 6B 20 4B 25 10
S 50 8S 40 1B 25 10B 20 4
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.
题意:
读题是最大的难点;给你n个账的记录,如果相同类且价格一样,则数量合并,取se价格从小到大前s个,再取b价格从大到小s个,最后先将s价格从大到小输出,再将b价格从大到小输出,读了好久没读懂,,,,
读懂题,这就是TMD水题;
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;struct node{int a;int va;} s[10010];struct node1{int b;int vb;}s1[10010];struct node2{int c;int vc;}s2[10010];struct node3{int d;int vd;}s3[10010];bool cmp(node x,node y){if(x.a!=y.a)return x.a>y.a;return x.va>y.va;}bool cmp1(node1 x,node1 y){if(x.b!=y.b)return x.b<y.b;return x.b>y.b;}bool cmp2(node2 x,node2 y){if(x.c!=y.c)return x.c>y.c;return x.vc>y.vc;}bool cmp3(node3 x,node3 y){if(x.d!=y.d)return x.d>y.d;return x.vd>y.vd;}int main(){int n,m,p1,p2,i=0,j=0,p,t;char ch;memset(s,0,sizeof(s));memset(s1,0,sizeof(s1));scanf("%d %d",&n,&m);t=n;while(n--){getchar();scanf("%c",&ch);if(ch=='B'){scanf("%d %d",&p1,&p2);s[i].a=p1;bool flag=true;for(p=0;p<i;p++){if(s[p].a==s[i].a){flag=false;break;}}if(flag){s[i].va=p2;i++;}else{s[p].va+=p2;s[i].va=0;}}else{scanf("%d %d",&p1,&p2);s1[j].b=p1;bool flag=true;for(p=0;p<j;p++){if(s1[p].b==s1[j].b){flag=false;break;}}if(flag){s1[j].vb=p2;j++;}else{s1[p].vb+=p2;s1[j].vb=0;}}}sort(s,s+i,cmp);sort(s1,s1+j,cmp1);t=min(t,m);p=i;for(i=0;i<min(t,j);i++){s2[i].c=s1[i].b;s2[i].vc=s1[i].vb;}sort(s2,s2+i,cmp2);for(j=0;j<i;j++)printf("S %d %d\n",s2[j].c,s2[j].vc);for(i=0;i<min(t,p);i++){s3[i].d=s[i].a;s3[i].vd=s[i].va;}sort(s3,s3+i,cmp3);for(j=0;j<i;j++)printf("B %d %d\n",s3[j].d,s3[j].vd);return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- jpa保存数据过慢的处理办法
- 结构体范例
- Android 进阶之路(我的博客文章目录)
- java基础常识
- 枚举-火柴棍等式
- CodeForces
- PAT(Advanced Level)1111. Online Map (30)
- Centos6.5编译安装Nginx1.8.0
- VS2015配置opengl最简单教程
- lumen5.4、PHP5.6+、win32、apache2.4+连接sql server配置
- BitMap的高效加载
- 前端开发工具sublime text 3
- 设置textview显示不同的字体和颜色
- Andorid Java-mail 发送邮件