原题链接:http://codeforces.com/contest/572/problem/B

题意

很迷,自行看题。

题解

看懂题就会做了

代码

#include<iostream>
#include<cstring>
#include<algorithm>
#define MAX_N 100005
using namespace std; int n,s; struct exchange {
public:
bool ty;
int p, q;
double sp; exchange(bool t, int pp, int qq) : ty(t), p(pp), q(qq), sp((double) p / q) { } exchange() { }
}; bool cmp(exchange a,exchange b) {
if (a.ty == b.ty) {
if (a.ty)return a.p > b.p;
else return a.p < b.p;
}
return a.ty < b.ty;
} int buy[MAX_N];
int sell[MAX_N]; exchange E0[MAX_N],E1[MAX_N];
int tot0,tot1; bool cmp0(exchange a,exchange b){
return a.p>b.p;
} int main(){
cin.sync_with_stdio(false);
cin>>n>>s;
for(int i=;i<n;i++){
char t;
int p,q;
cin>>t>>p>>q;
if(t=='B')buy[p]+=q;
else sell[p]+=q;
}
for(int i=;i<MAX_N;i++)
if(sell[i])
E0[tot0++]=exchange(,i,sell[i]);
for(int i=;i<MAX_N;i++)
if(buy[i])
E1[tot1++]=exchange(,i,buy[i]);
sort(E0,E0+tot0,cmp);
sort(E1,E1+tot1,cmp);
sort(E0,E0+min(s,tot0),cmp0);
sort(E1,E1+min(s,tot1),cmp0);
for(int i=;i<min(s,tot0);i++)cout<<"S "<<E0[i].p<<" "<<E0[i].q<<endl;
for(int i=;i<min(s,tot1);i++)cout<<"B "<<E1[i].p<<" "<<E1[i].q<<endl;
return ;
}

Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Order Book 模拟的更多相关文章

  1. Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Minimization dp

    原题链接:http://codeforces.com/contest/572/problem/D 题意 给你个数组A和n,k,问你排列A后,下面的最小值是多少. 题解 先排个序,要填充像1,1+k,1 ...

  2. Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Array 模拟

    题目链接:http://codeforces.com/contest/572/problem/A 题意 就给你两个数组,问你能不能从A数组中取出k个,B数组中取出m个,使得这k个都大于这m个. 题解 ...

  3. Codeforces Round #539&#542&#543&#545 (Div. 1) 简要题解

    Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...

  4. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

  5. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解

    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...

  6. Codeforces Round #317 (div 2)

    Problem A Arrays 思路:水一水. #include<bits/stdc++.h> using namespace std; ; int n1,n2,k,m,a[N],b[N ...

  7. Codeforces Round #317 (Div. 2) D Minimization (贪心+dp)

    D. Minimization time limit per test  2 seconds memory limit per test  256 megabytes input  standard ...

  8. Codeforces Round #317 (Div. 2) C Lengthening Sticks (组合,数学)

    一个合法的三角形的充要条件是a<b+c,其中a为最长的一边,可以考虑找出所有不满足的情况然后用总方案减去不合法的情况. 对于一个给定的总长度tl(一定要分完,因为是枚举tl,不分配的长度已经考虑 ...

  9. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

随机推荐

  1. Thinkphp5 获取执行的sql语句

    获取最后执行的sql语句 $str_order_action = db('order_action')->getLastSql(); //获取最后执行的sql语句 获取执行的sql语句 $ord ...

  2. Buffered Channels and Worker Pools

    原文链接:https://golangbot.com/buffered-channels-worker-pools/ buffered channels 带有缓冲区的channel 只有在缓冲区满之后 ...

  3. 《流畅的python》读书笔记,第一章:python数据模型

    这本书上来就讲了魔法方法,也叫双下方法.特殊方法,通过两个例子对让读者了解了双下方法的用法,更重要的是,让我一窥Python的语言风格和给使用者的自由度. 第一个例子:一摞Python风格的纸牌: i ...

  4. Leetcode 559. N叉树的最大深度

    题目链接 https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/description/ 题目描述 给定一个N叉树,找到其最大深度. ...

  5. Linux磁盘简介

    为一台服务器添加三块磁盘的体系结构情况 Linux系统中用free  -l 查看磁盘的状况 说明:   1)buffers为写入缓冲区,sync将缓冲区数据写入磁盘,cache为读出缓存. 2)cac ...

  6. spring boot + activeMq 邮件服务

    引入依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>s ...

  7. splay模板三合一 luogu2042 [NOI2005]维护数列/bzoj1500 [NOI2005]维修数列 | poj3580 SuperMemo | luogu3391 【模板】文艺平衡树(Splay)

    先是维修数列 题解看这里,但是我写的跑得很慢 #include <iostream> #include <cstdio> using namespace std; int n, ...

  8. [POJ 1003] Hangover C++解题

        Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95164   Accepted: 46128 De ...

  9. 大数据学习——spark-steaming学习

    官网http://spark.apache.org/docs/latest/streaming-programming-guide.html 1.1.  用Spark Streaming实现实时Wor ...

  10. day01_07.逻辑与字符串运算符

    &&(并且)====>发现&符号总是打错,记忆口令:&7(暗器),在数字7上面,在python中是and ||(或者)====>在python中是or . ...