cf509B Painting Pebbles

B. Painting Pebbles
time limit per test  1 second
memory limit per test  256 megabytes
input  standard input
output  standard output

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 test(s)
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

题意是给出一种染色方案,使得第i行有a[i]个元素,任意两行中任意两种颜色的元素个数相差不超过1
如果max-min>k,直接输出NO
否则直接每行模拟就好了
就是第i+tk的全染第i种颜色(t>=0)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void write(LL a)
{
    if (a<0){printf("-");a=-a;}
    if (a>=10)write(a/10);
    putchar(a%10+'0');
}
inline void writeln(LL a){write(a);printf("\n");}
int a[110];
int s[110];
int n,m,mx,mn=inf;
int main()
{
    n=read();m=read();
    for (int i=1;i<=n;i++)
    {
        a[i]=read();
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
    }
    if (mx-mn>m)
    {
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    for (int i=1;i<=n;i++)
    {
        memset(s,0,sizeof(s));
        int now=1;
        for (int j=1;j<=a[i];j++)
        {
            s[now++]++;
            if (now>m)now=1;
        }
        for (int j=1;j<=m;j++)
            for (int k=1;k<=s[j];k++)
                printf("%d ",j);
        printf("\n");
    }
    
}

 

转载于:https://www.cnblogs.com/zhber/p/4265692.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Lodash是一个JavaScript工具库,提供了很多常用的工具函数,可以方便地进行数据处理、函数式编程等操作。下面是一些常用的Lodash方法及其示例: 1. _.chunk(array, [size]): 把一个数组拆分成多个数组,每个数组包含指定数量的元素。 ``` _.chunk(['a', 'b', 'c', 'd'], 2); // => [['a', 'b'], ['c', 'd']] _.chunk(['a', 'b', 'c', 'd'], 3); // => [['a', 'b', 'c'], ['d']] ``` 2. _.compact(array): 去掉数组中的假值(false、null、0、""、undefined 和 NaN)。 ``` _.compact([0, 1, false, 2, '', 3]); // => [1, 2, 3] ``` 3. _.concat(array, [values]): 连接数组与其他值(可以是值或数组),生成一个新的数组。 ``` var array = [1]; var other = _.concat(array, 2, [3], [[4]]); console.log(other); // => [1, 2, 3, [4]] console.log(array); // => [1] ``` 4. _.difference(array, [values]): 返回在第一个数组中但不在其他数组中的元素。 ``` _.difference([2, 1], [2, 3]); // => [1] ``` 5. _.drop(array, [n=1]): 去掉数组前面的n个元素,返回剩余的数组。 ``` _.drop([1, 2, 3]); // => [2, 3] _.drop([1, 2, 3], 2); // => [3] _.drop([1, 2, 3], 5); // => [] _.drop([1, 2, 3], 0); // => [1, 2, 3] ``` 6. _.find(array, [predicate=_.identity], [fromIndex=0]): 遍历数组,找到第一个符合条件的元素并返回。 ``` var users = [ { 'user': 'barney', 'age': 36, 'active': true }, { 'user': 'fred', 'age': 40, 'active': false }, { 'user': 'pebbles', 'age': 1, 'active': true } ]; _.find(users, function(o) { return o.age < 40; }); // => { 'user': 'barney', 'age': 36, 'active': true } _.find(users, { 'age': 1, 'active': true }); // => { 'user': 'pebbles', 'age': 1, 'active': true } _.find(users, ['active', false]); // => { 'user': 'fred', 'age': 40, 'active': false } _.find(users, 'active'); // => { 'user': 'barney', 'age': 36, 'active': true } ``` 7. _.flatten(array): 把一个多维数组展开成一维数组。 ``` _.flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5] _.flattenDeep([1, [2, [3, [4]], 5]]); // => [1, 2, 3, 4, 5] ``` 8. _.groupBy(array, [iteratee=_.identity]): 把一个数组按照指定的条件进行分组,返回一个对象,对象的键为分组的条件,值为分组后的数组。 ``` var users = [ { 'user': 'barney', 'age': 36, 'active': true }, { 'user': 'fred', 'age': 40, 'active': false }, { 'user': 'pebbles', 'age': 1, 'active': true } ]; _.groupBy(users, 'active'); // => { 'true': [{ 'user': 'barney', 'age': 36, 'active': true }, { 'user': 'pebbles', 'age': 1, 'active': true }], 'false': [{ 'user': 'fred', 'age': 40, 'active': false }] } _.groupBy(users, function(o) { return o.age; }); // => { '1': [{ 'user': 'pebbles', 'age': 1, 'active': true }], '36': [{ 'user': 'barney', 'age': 36, 'active': true }], '40': [{ 'user': 'fred', 'age': 40, 'active': false }] } ``` 9. _.intersection([arrays]): 返回多个数组中都包含的元素。 ``` _.intersection([2, 1], [2, 3]); // => [2] _.intersection([2, 1], [2, 3], [1, 2]); // => [2] ``` 10. _.join(array, [separator=',']): 把数组中的所有元素用指定的分隔符连接成一个字符串。 ``` _.join(['a', 'b', 'c'], '~'); // => 'a~b~c' ``` 11. _.reverse(array): 把一个数组倒序排列。 ``` _.reverse([1, 2, 3]); // => [3, 2, 1] ``` 12. _.slice(array, [start=0], [end=array.length]): 返回一个从start开始、到end结束(不包含end)的子数组。 ``` _.slice([1, 2, 3], 0, 2); // => [1, 2] _.slice([1, 2, 3], 1); // => [2, 3] _.slice([1, 2, 3], -2); // => [2, 3] ``` 以上是一些常用的Lodash方法及其示例,Lodash还有很多其他的方法,可以查看官方文档来了解更多。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值