原题链接: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. 做ios工程时,把UI从xib移动到代码中遇到的问题

    由于四期要做多语言版本,带xib页面的工程做多语言版本比较麻烦,再加上现在已经习惯了代码中的viewdidload函数中初始化控件,所以就把两个页面从xib移到代码中去了. 在修改后加载页面会遇到ba ...

  2. 带权并查集:CF-2015 ACM Arabella Collegiate Programming Contest(F题)

    F. Palindrome Problem Description A string is palindrome if it can be read the same way in either di ...

  3. 一个Work Stealing Pool线程池的实现

    一.一般来说实现一个线程池主要包括以下几个组成部分: 1)线程管理器 :用于创建并管理线程池 . 2)工作线程 :线程池中实际执行任务的线程 . 在初始化线程时会预先创建好固定数目的线程在池中 ,这些 ...

  4. Navicat Premium 连接Oracle登入时候报ORA-12638: 身份证明检索失败的解决办法

    我的电脑是64位,oracle也是64位, plsql客户端是32位,oci连接的是32位 11.2版本: 用plsql 连接本地或远程数据库都没问题.在用 Navicat Premium 连本也没问 ...

  5. 正在创建模型,此时不可使用上下文“的解决办法。 正在创建模型,此时不可使用上下文。如果在 OnModelCreating 方法内使用上下文或如果多个线程同时访问同一上下文实例,可能引发此异常。请注意不

    //默认为: Database.SetInitializer<testContext>(null);//这里报错, 检查原因:catch(Exception ex) 错误提示: 基础连接未 ...

  6. TOJ1550: Fiber Communications

    1550: Fiber Communications  Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByteTotal ...

  7. hihoCoder挑战赛29

    多打打不同的比赛,找经验啊 题目4 : 不上升序列 时间限制:40000ms 单点时限:2000ms 内存限制:256MB 描述 给定一个长度为 n 的非负整数序列 a[1..n]. 你每次可以花费 ...

  8. ssh 远程执行绝对路径命令mysqld_multi 报my_print_defaults不存在

    通过SSH直接执行远程命令(这种方式会使用Bash的non-interactive + non-login shell模式)找不到命令参考:http://ghoulich.xninja.org/201 ...

  9. 【转】C#中的implicit 和 explicit

    The implicit and explicit keywords in C# are used when declaring conversion operators. Let's say tha ...

  10. 让Android软键盘默认进入英文键盘

    今天在做一个功能的 时候,需要输入法软键盘弹出后,需要进入英文输入界面. 可以通过设置EditText的输入类型为EMAIL来实现.     //将输入法切换到英文     edit.setInput ...