原题链接: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. 有关nmap的5个常用的扫描指令

    [以下IP可替换成需要被测试的IP网段] 1.ping扫描:扫描192.168.0.0/24网段上有哪些主机是存活的: nmap -sP 192.168.0.0/24   2.端口扫描:扫描192.1 ...

  2. Linux之crond 服务介绍

    在介绍crond之前,先科普一下什么是进程?什么是线程?什么是程序? 程序:程序是一组指令及参数的集合,指令按照既定的逻辑控制计算机运行.进程则是运行着的程序,是操作系统执行的基本单位.线程则是为了节 ...

  3. strcpy和strncpy用法和区别

    1. strcpy函数:顾名思义字符串复制函数:原型:extern char *strcpy(char *dest,char *src); 功能:把从src地址开始且含有NULL结束符的字符串赋值到以 ...

  4. HDU 5237 Base64 模拟

    题意: 输入一个明文串,输出\(k\)次\(Base64\)加密以后得到的串. 分析: 好像没什么Trick,直接模拟就行了. 注意:长度为\(3k+1\)的串,后面会有两个\(=\).长度为\(3k ...

  5. JAVA-基础(五) 更多工具集

    1.StringTokenizer(字符串标记) StringTokenizer实现枚举(Enumeration)接口.因此,给定一个输 入字符串,可以使用StringTokenizer对包含于其中的 ...

  6. LRESULT CALLBACK WndProc 窗口程序的 重点

    LRESULT CALLBACK WndProc Windows程序所作的一切,都是回应发送给窗口消息处理程序的消息.这是概念上的主要难点之一,在开始写作Windows程序之前,必须先搞清楚. 窗口消 ...

  7. Mysql - 安装及初始化设置

    1. 下载mysql-5.7.13-tar.gz http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x8 ...

  8. c/c++内存泄露的检测方法

    此文内容摘自 https://zhuanlan.zhihu.com/p/22664202 作为   从零开始的 JSON 库教程(三):解析字符串解答篇  的笔记 1A. Windows 下的内存泄漏 ...

  9. 九度oj 题目1348:数组中的逆序对

    题目描述: 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数. 输入: 每个测试案例包括两行: 第一行包含一个整数n,表示数组 ...

  10. 【图文】 使用ant编译和发布java项目

        开发JavaEE项目经常会碰到修改代码后,项目没有重新编译的问题.老大给指明了一个解决办法:用ant编译项目. ant是apache基金会下的一个项目,是基于Java语言的构建工具.      ...