CF799B T-shirt buying

题目大意

  有一些衣服,它们有价格、正面的颜色和反面的颜色。现有一群顾客按顺序来买存在某颜色且价格最低的衣服(不存在则不会买),求每个顾客花了多少钱。

思路

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

const int MAX_OBJ = 200010, MAX_COLOR = 5;
int TotObj;

struct Obj
{
    int Price, A, B;
    bool Vis;
}_objs[MAX_OBJ];

struct Cmp
{
    bool operator () (Obj *a, Obj *b)
    {
        return a->Price > b->Price;
    }
};

priority_queue<Obj*, vector<Obj*>, Cmp> q[3][MAX_COLOR];

int main()
{
    scanf("%d", &TotObj);
    for (int i = 1; i <= TotObj; i++)
        scanf("%d", &_objs[i].Price);
    for (int i = 1; i <= TotObj; i++)
    {
        scanf("%d", &_objs[i].A);
        q[1][_objs[i].A].push(_objs + i);
    }
    for (int i = 1; i <= TotObj; i++)
    {
        scanf("%d", &_objs[i].B);
        q[2][_objs[i].B].push(_objs + i);
    }
    int opCnt;
    scanf("%d", &opCnt);
    while(opCnt--)
    {
        int color;
        scanf("%d", &color);
        
        while(!q[1][color].empty() && q[1][color].top()->Vis)
            q[1][color].pop();
        Obj *obj1 = q[1][color].empty() ? NULL : q[1][color].top();
        while(!q[2][color].empty() && q[2][color].top()->Vis)
            q[2][color].pop();
        Obj *obj2 = q[2][color].empty() ? NULL : q[2][color].top();
        
        Obj *ans = obj1 && obj2 ? (obj1->Price < obj2->Price ? obj1 : obj2) : obj1 ? obj1 : obj2;
        bool Is1 = obj1 && obj2 ? (obj1->Price < obj2->Price) : (obj1 != NULL); 
        if (!ans)
            printf("-1 ");
        else
        {
            printf("%d ", ans->Price);
            ans->Vis = true;
            q[Is1 ? 1 : 2][Is1 ? ans->A : ans->B].pop();
        }
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/headboy2002/p/9427004.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值