当前位置:网站首页>*5-2 CCF 2014-12-3 集合竞价
*5-2 CCF 2014-12-3 集合竞价
2022-08-09 13:31:00 【叶萧白】
题目描述

源代码
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
const int N = 5000;
struct Order
{
double price;
int num;
int sell;//交易状态:0-买入 1-卖出 -1 取消
} order[N + 1];
vector<double> pricevec;//保存所有出现过的价格
int main()
{
char s[10];
int num = 0, t; //num记录数据的总条数
while (cin >> s) //buy 9.25 100
{
if (s[0] == 'c')//读入的是cancel
{
cin >> t;
order[t - 1].sell = -1;//取消第i行的交易
order[num].sell = -1;//cancel指令也必须要占一条
}
else
{
cin >> order[num].price >> order[num].num;
if (s[0] == 's')//卖出
order[num].sell = 1;
else
order[num].sell = 0;
pricevec.push_back(order[num].price);
}
num++;
}
double ans = 0;//开盘价
long long maxn = 0;//保存最大交易量
for (int i = 0; i < pricevec.size(); i++)
{
long long num_s = 0;//可卖出的股票数量
long long num_b = 0;//可买入的股票数量
for (int j = 0; j < num; j++)
{
if (order[j].sell == 1 && order[j].price <= pricevec[i])
num_s += (long long)order[j].num;
}
for (int j = 0; j < num; j++)
{
if (order[j].sell == 0 && order[j].price >= pricevec[i])
num_b += (long long)order[j].num;
}
num_s = min(num_s, num_b);
if (num_s > maxn)
{
maxn = num_s;
ans = pricevec[i];
}
else
{
if (num_s == maxn)
ans = max(ans, pricevec[i]);
}
}
printf("%.2f %lld\n", ans, maxn);
return 0;
}
边栏推荐
猜你喜欢
随机推荐
预约直播 I 阿里云EMR StarRocks 产品发布会
markdown学习1
(PC+WAP)带手机端pbootcms模板农业种植类网站
使用 compose 的 Canvas 自定义绘制实现 LCD 显示数字效果
Talking about CQRS Mode
Spark Sql之union
flink并行度知识点
12. cuBLAS Development Guide Chinese version--Level-1 functions asum() and axpy() in cuBLAS
Row of openharmony container components
openharmony容器组件之Column
Jetpack Compose - remember, mutableStateOf, rememberSaveable
openharmony容器组件之Row
Jetpack Compose——remember、mutableStateOf、rememberSaveable
ttemp
openharmony容器组件之Flex
oracle财务数据权限思考
The use of Jetpack Compose - Button (Button)
vs how to use a Button to link to another page
神经网络与深度学习(TensorFlow)
对百度的内容进行修改









