Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Order Book 模拟
原题链接: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 模拟的更多相关文章
- 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 ...
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Array 模拟
题目链接:http://codeforces.com/contest/572/problem/A 题意 就给你两个数组,问你能不能从A数组中取出k个,B数组中取出m个,使得这k个都大于这m个. 题解 ...
- Codeforces Round #539Ȟȟȡ (Div. 1) 简要题解
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...
- 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 ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解
Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...
- Codeforces Round #317 (div 2)
Problem A Arrays 思路:水一水. #include<bits/stdc++.h> using namespace std; ; int n1,n2,k,m,a[N],b[N ...
- Codeforces Round #317 (Div. 2) D Minimization (贪心+dp)
D. Minimization time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #317 (Div. 2) C Lengthening Sticks (组合,数学)
一个合法的三角形的充要条件是a<b+c,其中a为最长的一边,可以考虑找出所有不满足的情况然后用总方案减去不合法的情况. 对于一个给定的总长度tl(一定要分完,因为是枚举tl,不分配的长度已经考虑 ...
- Codeforces Round #237 (Div. 2) B题模拟题
链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...
随机推荐
- python3.6:DLL load failed:找不到指定的模块(from PyQt5 import QtCore)
本人小白搭建pyqt环境时遇到问题 运行代码 from PyQt5 import QtCore' 发现错误 ImportError: DLL load failed: 找不到指定的模块 这个问题折磨了 ...
- CentOS 7.0 使用 yum 安装 MariaDB 及 简单配置
1.安装MariaDB 安装命令 yum -y install MariaDB-server MariaDB-client 安装完成MariaDB,首先启动MariaDB 设置开机启动 接下来进行Ma ...
- jmeter中重要组件及其执行顺序
jmeter中重要组件有:Sampler,计时器,前置处理器和后置处理器,断言,Controller,Listener和配置原件. 同类组件之间是从上到下的顺序执行,不同组件之间是按照以下的顺序执行的 ...
- UVa 11695 树的直径 Flight Planning
题意: 给出一棵树,删除一条边再添加一条边,求新树的最短的直径. 分析: 因为n比较小(n ≤ 2500),所以可以枚举删除的边,分裂成两棵树,然后有这么一个结论: 合并两棵树后得到的新树的最短直径为 ...
- 新线程 handler
class CalculateThread extends Thread { private Handler handler; @Override public void run() { super. ...
- 手撸一套纯粹的CQRS实现
关于CQRS,在实现上有很多差异,这是因为CQRS本身很简单,但是它犹如潘多拉魔盒的钥匙,有了它,读写分离.事件溯源.消息传递.最终一致性等都被引入了框架,从而导致CQRS背负了太多的混淆.本文旨在提 ...
- Selenium WebDriver- 操作JavaScript的prompt弹窗(使用率低)
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- 大数据学习——spark运营案例
iplocation需求 在互联网中,我们经常会见到城市热点图这样的报表数据,例如在百度统计中,会统计今年的热门旅游城市.热门报考学校等,会将这样的信息显示在热点图中. 因此,我们需要通过日志信息(运 ...
- Android 资源文件local.properties使用以及Gradle文件中的值、Manifests文件中的值
这篇也是因为Gradle存储密钥问题一路填坑总结的,期初连.properties创建都有疑问 因为当时是在Android下查看新建的properties一直没法看到 因为Gradle Scripts是 ...
- mybatis学习(八)——resultMap之association&&collection解析
一.resultMap的使用 resultMap 也是定义返回值类型,返回值为用户自定义的类型,可用于解决JavaBean中的属性名和数据库中的列名不一致的情况 之前对于JavaBean中属性名和数据 ...