CCF 集合竞价

21 篇文章 0 订阅
20 篇文章 0 订阅

题目

在这里插入图片描述

思想

没太读懂题目的意思。除了几条对字符串的解释之外,有几个点是解题的关键。

  1. 此时的开盘成交量出价至少为p0的买单的总股数所有出价至多为p0的卖单的总股数之间的较小值。----->最后输出的应该是两者的最小值。
  2. 你的程序需要确定一个开盘价,使得开盘成交量尽可能地大,如果有多个符合条件的开盘价,你的程序应当输出最高的那一个。 —>输出成交量尽量大的一个,在成交量相同的情况下,成交价尽量大。

代码

#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 5010;

struct Record {
	//用于标记该记录时买(1)或者卖(0)
	int type;
	//表示价格
	double p;
	//表示数量
	int s;
	//用于标记是否被删除
	//false 表示没有
	//true	表示删除
	bool is_del;
} d[N];
int n = 0;


int main() {
	string type;
	while (cin >> type) {

		if (type == "buy") {
			double p;
			int s;
			cin >> p;
			cin >> s;
			d[++n] = {1, p, s};
		} else if (type == "sell") {
			double p;
			int s;
			cin >> p;
			cin >> s;
			d[++n] = {0, p, s};
		} else {
			int id;
			cin >> id;
			d[id].is_del = true; //撤销id条操作
			d[++n].is_del = true; //将该cancel设置为true
		}
	}
	double resp = 0;
	long long ress = 0;
	for (int i = 1; i <= n; i++) {
		//如果该记录已经被撤销就不进行操作
		if (d[i].is_del == false) {
			//以当前记录的价格为出手价与其他的记录中的价格比较
			double p = d[i].p;
			//s1表示buy的股数,s2表示sell的股数
			long long s1 = 0, s2 = 0;
			for (int j = 1; j <= n; j++) {
				if (d[j].is_del == false) {
					if (d[j].type == 1 && d[j].p >= p) {
						s1 += d[j].s;
					} else if (d[j].type == 0 && d[j].p <= p) {
						s2 += d[j].s;
					}
				}
			}
			long long temp = fmin(s1, s2);
			if (temp > ress || (temp == ress && p > resp)) {
				ress = temp;
				resp = p;
			}
		}
	}
	printf("%.2lf %lld\n", resp, ress);
	return 0;
}

后记

菜,所以只会暴力的方法,下面给出y总代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值