CodeForces 509B Painting Pebbles
来源:互联网 发布:数据挖掘在的应用 编辑:程序博客网 时间:2024/06/05 12:45
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 41 2 3 4
YES11 41 2 41 2 3 4
5 23 2 4 1 3
NO
5 43 2 4 3 5
YES1 2 31 31 2 3 41 3 41 1 2 3 4
大致题意是给定颜色的种类,问是否能用这些颜色涂石子
如果是,输出满足条件的一种涂色方案
使任意两堆石子中涂有任意颜色的石子数的差值至多为一个
有一点很容易发现:当这些石堆中有两堆的石子数差值的绝对值大于给的颜色数时,这样的方案显然是不存在的
而对于其它情况,方案似乎是存在的(其实我还没想出严格的证明方法o(╯□╰)o)
那么假定对于其它情况这样的方案是存在的
该怎么输出涂色方案捏
为了让答案更清晰
我们有序地对石子进行涂色
对于任一堆石子,从下至上,我们都从颜色1开始涂,一种颜色涂一块石子
例如总共有4块石子,那么从下到上的颜色分别为1,2,3,4
似不似很简单~(≧▽≦)/~
那么问题来了,如果我们现在只有3种或更少的颜色怎么办o(╯□╰)o
很容易想到再从颜色1开始继续按顺序涂
例如总共有5块石子,而颜色总数只有3种,那么从下到上的颜色分别为1,2,3,1,2
由于一堆石块中各石块的涂色顺序与题目是无关的
因此,当我们按照这样的方法涂色时,给出的必定是符合题意的方案(咦,前面刚说没想出证明方法来着怎么就证出来了╮(╯▽╰)╭)
代码如下:
#include<iostream>using namespace std;const int maxn = 100+5;int main() { int n, k, min_num = maxn, max_num = -maxn; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > max_num) max_num = a[i]; if (a[i] < min_num) min_num = a[i]; } if (max_num - min_num > k) { cout << "NO" << endl; return 0; } cout << "YES" << endl; for (int i = 0; i < n; i++) { int first = 1; for (int j = 0; j < a[i]; j++) { if (first) first = 0; else cout << " "; cout << j%k+1; } cout << endl; } return 0;}
- CodeForces 509B Painting Pebbles
- CodeForces 509B Painting Pebbles
- CodeForces-509B Painting Pebbles
- CodeForces 509B Painting Pebbles
- Codeforces 509 B Painting Pebbles 贪心
- 【水题】Codeforces Round #289 509B Painting Pebbles
- CF 509B Painting Pebbles
- B. Painting Pebbles(Codeforces Round #289 )
- CF 509B(Painting Pebbles-贪心)
- B. Painting Pebbles
- B - Painting Pebbles
- B. Painting Pebbles
- Codeforces Round #289 (Div. 2)-B. Painting Pebbles
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
- Codeforces Round #289 (Div. 2, ACM ICPC Rules) -- B. Painting Pebbles (贪心)
- Codefroecs 289 div2 B. Painting Pebbles(贪心)
- [cf509B]Painting Pebbles
- codeforces 282B - Painting Eggs
- 0009 嘿嘿
- [人眼检测] high confidence visual recognition of persons by a test of statistical independence
- 【node.js学习】--(6)--Bootstrap
- POJ 2492--A Bug's Life 【并查集,向量偏移】
- UVa 589 - Pushing Boxes
- CodeForces 509B Painting Pebbles
- 计算机网络第五章
- HDU 2151--Worm【动态规划】
- uva 10375 选择与除法
- 直接序列扩频通信(DSSS)
- spring中依赖注入方式总结
- 【课堂笔记】C++程序设计- 第一章-绪论
- 微信支付V2账单查询接口orderquery示例代码
- 位操作基础篇之位操作全面总结