第三次CCF计算机软件能力认证 集合竞价 (模拟题)

分析

将每只股票存入结构体数组d中,然后枚举每个价格低于它的卖出数量和高于它的买入数量,每次二者取最小值,同时更新最大的开盘价。

C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 5e3+10;
int idx;
long long ansn=-1;
struct node{
    int type;
    double price;
    int num;
    bool is_del=false;
    
}d[N];
double ansp=-1;
int main()
{
    string type;
    while (cin >> type)
    {
        if(type=="buy")
        {
            double p;
            int s;
            cin >> p >> s;
            d[++idx]={1, p, s};
        }
        else if(type=="sell")
        {
            double p;
            int s;
            cin >> p >> s;
            d[++idx]={2, p, s};
        }
        else
        {
            int id;
            cin >> id;
            d[id].is_del = true;
            d[++idx].is_del = true;
            d[idx].type=3;
        }
    }
    long long temp1=0,temp2=0;
    for(int i=1;i<=idx;i++)
    {
        if(!d[i].is_del)    //当前股票没有作废,就统计低于它的卖出数量和高于它的买入数量
        {
            temp1=0,temp2=0;
            for(int j=1;j<=idx;j++)
            {
                if(!d[j].is_del)
                {
                    if(d[j].type==1 && d[j].price>=d[i].price) temp1+=d[j].num;  //买入数量
                    else if(d[j].type==2 && d[j].price<=d[i].price) temp2+=d[j].num;    //卖出数量
                }
            }
            long long t=min(temp1,temp2);   //取二者最小值
            if(t>ansn || (t==ansn && d[i].price>ansp))
            {
                ansn=t;
                ansp=d[i].price;
            }
        }
    }
    printf("%.2lf %lld",ansp,ansn);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jay_fearless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值