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 }
     
     
  • 相关阅读:
    gulp-css-spriter 将css代码中的切片图片合并成雪碧图
    通过JS模拟select表单,达到美化效果[demo]
    jQuery拖拽 & 弹出层
    sublime text 快速编码技巧 GIT图
    原生JS不到30行,实现类似javascript MVC的功能-minTemplate
    javascript拖拽原理与简单实现方法[demo]
    滚动焦点图实现原理和实践[原创视频]
    谈一谈值类型与引用类型和装箱与拆箱
    【原创】asp.net内部原理(三) 第三个版本 (最详细的版本)
    由JS函数返回值引发的一场”血案"
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11671255.html
Copyright © 2011-2022 走看看