zoukankan      html  css  js  c++  java
  • CF 799B T-shirt buying

    传送门:https://www.luogu.org/problemnew/show/CF799B

    题中说每一个人只要一种颜色,无论正反面,所以我们只要贪心的选包含这种颜色中且没有被别的人选过的价格最小的衣服就行了。

    实现只要每一种颜色开一个优先队列,然后给每一件衣服标号,然后对于每一个人,查看他要的颜色的优先队列,如果没被选走,就拿这件衣服。

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<cctype>
     7 #include<vector>
     8 #include<stack>
     9 #include<queue>
    10 using namespace std;
    11 #define enter printf("
    ")
    12 #define space printf(" ")
    13 #define Mem(a) memset(a, 0, sizeof(a))
    14 typedef long long ll;
    15 typedef double db;
    16 const int INF = 0x3f3f3f3f;
    17 const db eps = 1e-8;
    18 const int maxn = 2e5 + 5;
    19 inline ll read()
    20 {
    21     ll ans = 0;
    22     char ch = getchar(), last = ' ';
    23     while(!isdigit(ch)) {last = ch; ch = getchar();}
    24     while(isdigit(ch))
    25     {
    26         ans = ans * 10 + ch - '0'; ch = getchar();    
    27     }
    28     if(last == '-') ans = -ans;
    29     return ans;
    30 }
    31 inline void write(ll x)
    32 {
    33     if(x < 0) x = -x, putchar('-');
    34     if(x >= 10) write(x / 10);
    35     putchar('0' + x % 10);
    36 }
    37 
    38 int n, m;
    39 struct Node
    40 {
    41     int id;
    42     ll p;
    43     bool operator < (const Node& other)const
    44     {
    45         return p > other.p ||(p == other.p && id > other.id);
    46     }
    47 }t[maxn];
    48 priority_queue<Node> sh[5];
    49 bool vis[maxn];
    50 
    51 int main()
    52 {
    53     n = read();
    54     for(int i = 1; i <= n; ++i) {t[i].p = read(); t[i].id = i;}
    55     for(int i = 1; i <= n; ++i) {int a = read(); sh[a].push(t[i]);}        //没必要记录没每一件衣服的颜色 
    56     for(int i = 1; i <= n; ++i) {int b = read(); sh[b].push(t[i]);}
    57     m = read();
    58     for(int i = 1; i <= m; ++i)
    59     {
    60         bool flag = 0;
    61         int c = read();
    62         while(!sh[c].empty())
    63         {
    64             Node x = sh[c].top(); sh[c].pop();
    65             if(!vis[x.id]) {vis[x.id] = 1; flag = 1; write(x.p); enter; break;}
    66         } 
    67         if(!flag) {printf("-1
    "); continue;}
    68     }
    69     return 0;
    70 }
  • 相关阅读:
    ruby
    Ajax的基本请求/响应模型
    面向GC的Java编程(转)
    linux中fork()函数详解(转)
    详细解析Java中抽象类和接口的区别(转)
    MQ队列堆积太长,消费不过来怎么办(转)
    消息队列软件产品大比拼(转)
    mac地址和ip地址要同时存在么?
    DP刷题记录(持续更新)
    ZR979B. 【十联测 Day 9】唯一睿酱
  • 原文地址:https://www.cnblogs.com/mrclr/p/9414659.html
Copyright © 2011-2022 走看看