zoukankan      html  css  js  c++  java
  • Codeforces Round #289 (Div. 2, ACM ICPC Rules)——B贪心——Painting Pebbles

    There are n piles of pebbles on the table, the i-th pile contains ai pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c in pile i and number of pebbles of color c in pile j is at most one.

    In other words, let's say that bi, c is the number of pebbles of color c in the i-th pile. Then for any 1 ≤ c ≤ k1 ≤ i, j ≤ n the following condition must be satisfied |bi, c - bj, c| ≤ 1. It isn't necessary to use all k colors: if color c hasn't been used in pile i, then bi, c is considered to be zero.

    Input

    The first line of the input contains positive integers n and k (1 ≤ n, k ≤ 100), separated by a space — the number of piles and the number of colors respectively.

    The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) denoting number of pebbles in each of the piles.

    Output

    If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) .

    Otherwise in the first line output "YES" (without quotes). Then n lines should follow, the i-th of them should contain ai space-separated integers. j-th (1 ≤ j ≤ ai) of these integers should be equal to the color of the j-th pebble in the i-th pile. If there are several possible answers, you may output any of them.

    Sample Input

    Input
    4 4
    1 2 3 4
    Output
    YES
    1
    1 4
    1 2 4
    1 2 3 4
    Input
    5 2
    3 2 4 1 3
    Output
    NO
    Input
    5 4
    3 2 4 3 5
    Output
    YES
    1 2 3
    1 3
    1 2 3 4
    1 3 4
    1 1 2 3 4
    /*
       把个数从少到多进行排序,用来判断前后是否可能,只要统计循环的次数以及循环到哪里了就可以轻松判断,如果循环次数差的大于1并且差的位数也大于1那么肯定是不行的,for example:
       m = 2 a[1] = 2, a[2] = 5
       1 2   b[1] = 1  c[1] = 0;
       1 2 1 2 1 b[1] = 2 c[2] = 1
       如果循环次数差的大于2也肯定不行这个显然
       所以先判是否可以如果可以直接就根据循环和位输出当前值
    */
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    struct edge{
        int a, b, c;
    }G[110];
    
    bool cmp(edge i, edge j){
        return i.a < j.a;
    }
    int main()
    {
        int n, m;
        int a[110];
        int b[110];
        int c[110];
        while(~scanf("%d%d", &n, &m)){
            for(int i = 1; i <= n ; i++)
                scanf("%d", &a[i]);
            for(int i = 1; i <= n; i++){
                int k = a[i] / m;
                int t = a[i] % m ;
                b[i] = k;
                c[i] = t;
            }
            for(int i = 1; i <= n ;i++){
                G[i].a = a[i];
                G[i].b = b[i];
                G[i].c = c[i];
            }
            sort(G + 1, G + n + 1, cmp);
           /* for(int i = 1; i <= n ;i++){
                printf("%d %d %d", G[i].a, G[i].b, G[i].c);
               puts("");
            }
            */
            int flag = 0;
            for(int i = 1; i <= n ; i++){
                for(int j = i + 1; j <= n ; j++){
                    if(G[j].b > G[i].b && G[j].c > G[i].c || G[j].b - G[i].b >= 2 ){
                       flag = 1 ;
                       break;
                    }
                }
                if(flag == 1)
                    break;
            }
            if(flag == 1) {printf("NO
    "); }
            else {
                printf("YES
    ");
                for(int i = 1; i <= n ; i++){
                    for(int j = 1; j <= b[i]; j++){
                        for(int k = 1; k <= m; k++)
                            printf("%d ",k);
                    }
                    for(int j = 1; j <= c[i]; j++)
                    printf("%d ", j);
                puts("");
                }
            }
        }
        return 0;
    }
    
    
            
    

      

  • 相关阅读:
    Mvcpager以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”。
    骆驼男鞋怎么样,骆驼男鞋售后逆天,骆驼男鞋维修36天无结果。程序员屌丝的维权之路,直播。。。。。。
    IOS7状态栏StatusBar官方标准适配方法
    iphone原生cookie处理
    拼接语句单引号里面如何用单引号
    判断Linux 系统负荷是否过载
    sys用户无法远程登陆
    ORA-12838: cannot read/modify an object after modifying it in parallel
    ORA-19504: failed to create file "/u01/backup/db_0_20190603_1" ORA-27038: created file already exists
    oracle中job无法正常运行,如何排查
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4652404.html
Copyright © 2011-2022 走看看