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=0;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=0;i<MAX_N;i++) if(sell[i]) E0[tot0++]=exchange(0,i,sell[i]); for(int i=0;i<MAX_N;i++) if(buy[i]) E1[tot1++]=exchange(1,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=0;i<min(s,tot0);i++)cout<<"S "<<E0[i].p<<" "<<E0[i].q<<endl; for(int i=0;i<min(s,tot1);i++)cout<<"B "<<E1[i].p<<" "<<E1[i].q<<endl; return 0; }