# CCF 201412-3 集合竞价

CCF 201412-3 集合竞价 传送门

2018-9-7日更新。谢谢一位同学的提示，已将所有int改为long long, 得了100分。

1. 对命令进行处理, 改取消的取消, 可以stringstream方便读取字符串中的string double int.

80分Code

#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

struct Node {
double money;
long long num;
Node (double m, long long n): money(m), num(n) {}
};

bool cmp(Node x, Node y)
{
return x.money < y.money;
}

string str[5005];

int main()
{
long long t = 0;
while (getline(cin, str[++t])) {
if (str[t][0] == 'c') {
long long in = 7, line = 0;
for (long long i = in; i < str[t].size(); ++i) {
line = line*10 + int(str[t][i] - '0');
}
str[line] = "";
str[t] = "";
}
}
for (long long i = 1; i <= t; ++i) {
stringstream sin(str[i]);
string tmp;
double money;
long long num;
sin >> tmp >> money >> num;
if (str[i][0] == 's') sell.push_back(Node(money, num));
else if (str[i][0] == 'b') buy.push_back(Node(money, num));
}
sort(sell.begin(), sell.end(), cmp);
for (long long i = buy.size() - 1; i >= 0; --i)
sum_sell[0] = sell[0].num;
for (long long i = 1; i < sell.size(); ++i)
sum_sell[i] = sum_sell[i - 1] + sell[i].num;
double ans_mny = 0;
long long ans_cnt = 0;
for (long long i = 0, j = 0; i < buy.size(); ++i) {
while (sell[j].money <= bmo) {
if (j == sell.size() - 1 || sell[j+1].money > bmo) {
if (ans_cnt <= min(sum_buy[i], sum_sell[j])) {
ans_mny = bmo;
}
break;
}
j++;
}
}
printf("%.2lf %lld", ans_mny, ans_cnt);
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120