zoukankan      html  css  js  c++  java
  • SuperHyperMarket Gym

    The day of opening of the greatest shop in the world is coming. To show the full potential of their shop, in particular, the unbelievable speed of the cash desks, the owners of the shop came up with the following move: n most average customers will be let into the shop, and the cash desks will be opened only after all customers will choose their purchases and take their places in the queues. The problem is that if the customers walk along the cash desks and choose the optimal queue, the process can last for several hours. That's why you are asked to choose queues for all customers automatically.

    The sociologists told you how the average customers choose the queue: they look at the number of people in the queue and at the number of the purchases of the last two people in it. Formally, the customer chooses the cash desk i for which the value xi = ci·p is minimal. Here, ci is the number of people in the i-th queue, and p — is the average (by the average customer's definition) number of purchases of one person in the queue. The value of p is calculated by two last people in the queue: p = (p1 + p2) / 2, if there are two or more people in the queue (p1 and p2 are the numbers of purchases of the last two people), p = p1, if there is only one customer in the queue, and p = 0 if the queue is empty. If there are several cash desks with minimal xi, the customer chooses the one with the minimal number i.

    After the customers choose their queue, they don't go anywhere out of it.

    Input

    The first line contains two space-separated integers n and k (1 ≤ n, k ≤ 105) — the number of customers and the number of cash desks in the shop.

    The next line contains n space-separated integers pj (1 ≤ pj ≤ 1000) — the numbers of purchases of the j-th customer in the chronological order. Every customer chooses his queue before the next customer starts doing it.

    Output

    Write n space-separated integers in one line. The i-th number should be equal to the number of cash desk where the i-th customer will go using the criterion described in the problem.

    Examples

    Input
    5 2
    1 3 1 2 3
    Output
    1 2 1 1 2 
    Input
    5 7
    1 3 1 2 3
    Output
    1 2 3 4 5 
    典型的优先队列
     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 struct item
     6 {
     7     long long num, top, cou;
     8     double data;
     9     long long a[5];
    10     bool operator < (const item& a) const
    11     {
    12         return data > a.data || (data==a.data && num>a.num);
    13     }
    14 }ite;
    15 
    16 priority_queue<item>str;
    17 
    18 int main()
    19 {
    20     long long n, k, i, x;
    21     scanf("%lld %lld", &n, &k);
    22     for(i=1; i<=n; i++)
    23     {
    24         scanf("%lld", &x);
    25         if(i<=k)
    26         {
    27             printf("%lld", i);
    28             ite.top = 0;
    29             ite.num = i;
    30             ite.cou = 1;
    31             ite.a[ite.top++] = x;
    32             ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
    33         }
    34         else
    35         {
    36             ite = str.top();
    37             str.pop();
    38             printf("%lld", ite.num);
    39             ite.cou++;
    40             if(ite.top<2)
    41             {
    42                 ite.a[ite.top++] = x;
    43                 ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
    44             }
    45             else
    46             {
    47                 ite.a[0] = ite.a[1];
    48                 ite.a[1] = x;
    49                 ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
    50             }
    51         }
    52         str.push(ite);
    53         if(i==n) printf("
    ");
    54         else printf(" ");
    55     }
    56     return 0;
    57 }
     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 struct item
     6 {
     7     long long num, top, cou;
     8     double data;
     9     long long a[5];
    10     bool operator < (const item& a) const
    11     {
    12         return data > a.data || (data==a.data && num>a.num);
    13     }
    14 }ite;
    15 
    16 priority_queue<item>str;
    17 
    18 int main()
    19 {
    20     long long n, k, i, x;
    21     scanf("%lld %lld", &n, &k);
    22     for(i=1; i<=n; i++)
    23     {
    24         scanf("%lld", &x);
    25         if(i<=k)
    26         {
    27             printf("%lld", i);
    28             ite.top = 0;
    29             ite.num = i;
    30             ite.cou = 1;
    31             ite.a[ite.top++] = x;
    32             ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
    33         }
    34         else
    35         {
    36             ite = str.top();
    37             str.pop();
    38             printf("%lld", ite.num);
    39             ite.cou++;
    40             if(ite.top<2)
    41             {
    42                 ite.a[ite.top++] = x;
    43                 ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
    44             }
    45             else
    46             {
    47                 ite.a[0] = ite.a[1];
    48                 ite.a[1] = x;
    49                 ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
    50             }
    51         }
    52         str.push(ite);
    53         if(i==n) printf("
    ");
    54         else printf(" ");
    55     }
    56     return 0;
    57 }
     
     
  • 相关阅读:
    十分钟上手-搭建vue开发环境(新手教程)
    如何去掉bootstrap table中表格样式中横线竖线
    进阶攻略|前端最全的框架总结
    进阶攻略|前端完整的学习路线
    2018上半年GitHub上最热门的开源项目
    三分钟教你学会如何将密文解码成明文
    【前端图表】echarts实现散点图x轴时间轴
    IOS应用开发版本控制工具之Versions使用
    从零开始学ios开发(十七):Storyboards(上)
    ios按钮点击后翻转效果
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11671255.html
Copyright © 2011-2022 走看看