cf509B 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 ≤ k, 1 ≤ 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.
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.
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.
4 4
1 2 3 4
YES
1
1 4
1 2 4
1 2 3 4
5 2
3 2 4 1 3
NO
5 4
3 2 4 3 5
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");
} }
cf509B Painting Pebbles的更多相关文章
- B. Painting Pebbles
B. Painting Pebbles time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 509 B题 Painting Pebbles
转载地址:http://blog.csdn.net/nike0good/article/details/43449739 B. Painting Pebbles time limit per test ...
- codeforces 507B. Painting Pebbles 解题报告
题目链接:http://codeforces.com/problemset/problem/509/B 题目意思:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色 ...
- 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...
- 【codeforces 509B】Painting Pebbles
[题目链接]:http://codeforces.com/contest/509/problem/B [题意] 给n鹅卵石染色; 有k种颜色可供选择; 问你有没有染色方案; 使得各个堆的鹅卵石里面,第 ...
- codeforces509B
Painting Pebbles CodeForces - 509B There are n piles of pebbles on the table, the i-th pile contains ...
- Codeforces Round #289 Div 2
A. Maximum in Table 题意:给定一个表格,它的第一行全为1,第一列全为1,另外的数满足a[i][j]=a[i-1][j]+a[i][j-1],求这个表格中的最大的数 a[n][n]即 ...
- CF448C Painting Fence (分治递归)
Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...
- [译]使用Continuous painting mode来分析页面的绘制状态
Chrome Canary(Chrome “金丝雀版本”)目前已经支持Continuous painting mode,用于分析页面性能.这篇文章将会介绍怎么才能页面在绘制过程中找到问题和怎么利用这个 ...
随机推荐
- Ubuntu+Win7+Samba实现文件共享
Samba是Ubuntu和Windows进行网络共享的工具,比如分享打印机,互相之间传输资料文件. 安装samba sudo apt-get install samba 查看samba是否安装成功 s ...
- DTN学习的一些有用链接
1.DTN研究组,该网站提供了一些代码,有NS2上的实现,也有用java实现的源码. http://www.dtnrg.org/wiki/Code 2.DTN实现的另一个版本,与ONE比较,目前还没用 ...
- Android ArrayAdapter MultiAutoCompleteTextView
MultiAutoCompleteTextView 继承自AutoCompleteTextView,它和AutoCompleteTextView不同的就是能处理多个输入字段,如发送短信界面的联系人列表 ...
- Qemu之Network Device全虚拟方案一:前端网络流的建立
KVM在I/O虚拟化方面,传统的方式是使用Qemu纯软件的方式来模拟I/O设备,当中包含常常使用的网卡设备.这次我们重点分析Qemu为实现网络设备虚拟化的全虚拟化方案.本主题从三个组成方面来完整描写叙 ...
- yii图片上传
http://wuhai.blog.51cto.com/2023916/953300 首先感谢这里的博主,提供了思路,不过在调用 $model->b_image->extensionNam ...
- C++输出hello world 详细注释
/* #include<iostream> #:预处理标志,后面跟预处理指令,include:预处理指令,包含 <iostream>:c++头文件,输入输出流 这行的作用就是在 ...
- MVP模式 详解 案例
介绍 MVC: View:对应于布局文件 Model:业务逻辑和实体模型 Controllor:对应于Activity 实际上关于该布局文件中的数据绑定的操作,事件处理的代码都在Activity中,造 ...
- div中实现居中
今天纠结了大半天的居中,把学到的先记录下来,还没完全弄清楚,发现网上原创的技术贴并不算多,大多都是相互转载.(ps.先安利一个大神的帖集,昨天才发现的,内容丰富,语言,呃...很幽默,一般都是图文并茂 ...
- 腾讯云升级到PHP7
1.删除之前安装的PHP yum remove php* php-common 2.安装yum源 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel ...
- state模式理解
state模式应用场景 条件判断很多的情况 比如有很多if else语句:switch case语句等等. 如果以后业务越来越复杂,条件判断有100多个,每种条件的处理逻辑很复杂,不止一个业务逻辑会重 ...