zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    钱多,人傻,快来快来
    Rabbitmq的使用及Web监控工具使用
    Fiddler的配置
    哪个微信编辑器比较好用?
    js手机号批量滚动抽奖代码实现
    Webform和MVC,为什么MVC更好一些?
    自学MVC看这里——全网最全ASP.NET MVC 教程汇总
    客如云系统访谈
    Asp.Net MVC2.0 Url 路由入门---实例篇
    架设自己的FTP服务器 Serv-U详细配置图文教程
  • 原文地址:https://www.cnblogs.com/headboy2002/p/9427004.html
Copyright © 2011-2022 走看看