题目传送门

 /*
题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles,
使得任意两个piles,用颜色c填充的pebbles数量之差 <= 1。
如果不填充某种颜色,就默认数量为0。
1. 贪心:如果个数之间超过k个,那么填充什么颜色都会大于1,巧妙地思维
详细解释:http://blog.csdn.net/haoliang94/article/details/43672617
2. 比较每种填充颜色在n组里使用最多和最少的,若差值<=1,则YES,否则NO
详细解释:http://www.cnblogs.com/windysai/p/4265469.html
*/
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
using namespace std; const int MAXN = + ;
const int INF = 0x3f3f3f3f;
int a[MAXN]; int main(void)
{
#ifndef ONLINE_JUDGE
freopen ("B.in", "r", stdin);
#endif int n, k;
while (~scanf ("%d%d", &n, &k))
{
int mx = -; int mn = INF;
for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i]);
if (mx < a[i]) mx = a[i];
if (mn > a[i]) mn = a[i];
} if (mx - mn <= k)
{
puts ("YES");
for (int i=; i<=n; ++i)
{
int t = ;
for (int j=; j<=a[i]; ++j)
{
printf ("%d%c", ++t, (j==a[i]) ? '\n' : ' ');
if (t == k) t = ;
}
}
}
else
puts ("NO");
} return ;
}

 #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
using namespace std; const int MAXN = + ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int cnt[MAXN];
vector <int> v[MAXN]; int main(void)
{
#ifndef ONLINE_JUDGE
freopen ("B.in", "r", stdin);
#endif int n, k;
while (~scanf ("%d%d", &n, &k))
{
for (int i=; i<=MAXN; ++i)
v[i].clear (); for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i]);
memset (cnt, , sizeof (cnt));
int t = ;
for (int j=; j<=a[i]; ++j)
{
cnt[++t]++;
if (t == k) t = ;
}
for (int j=; j<=k; ++j)
{
v[j].push_back (cnt[j]);
}
} bool flag = true;
vector<int>:: iterator it1, it2;
for (int i=; i<=k; ++i)
{
sort (v[i].begin (), v[i].end ());
it1 = v[i].end () - ;
it2 = v[i].begin ();
if (*it1 - *it2 > )
{
flag = false; break;
}
} if (flag)
{
puts ("YES");
for (int i=; i<=n; ++i)
{
int t = ;
for (int j=; j<=a[i]; ++j)
{
printf ("%d%c", ++t, (j==a[i]) ? '\n' : ' ');
if (t == k) t = ;
}
}
}
else
puts ("NO");
} return ;
}

解法2

贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles的更多相关文章

  1. codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...

  2. Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

    E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table

    题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...

  4. Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】

    A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  6. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  7. 贪心 Codeforces Round #301 (Div. 2) B. School Marks

    题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...

  8. 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

    题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...

  9. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

随机推荐

  1. oc弹出框显示提示消息

    - (void)ShowHUDTitle:(NSString *)title andDelay:(NSTimeInterval)delayTime { if (HUD) { [HUD removeFr ...

  2. Redis 数据持久化(一)

    Redis的模块化开发设计的还是相当不错的,在Bio.h和Bio.c文件中定义了一个多线程的文件任务处理模块,在添加和处理任务的时候使用互斥锁和条件变量进行的同步,而且本身也支持多线程,这个模块的支持 ...

  3. ThinkPHP入门(二)

    smarty使用 smarty引入流程 1. 控制器IndexAction.class.php function index() $this -> display(); (父类Action的di ...

  4. async/await 异步编程(转载)

    转载地址:http://www.cnblogs.com/teroy/p/4015461.html 前言 最近在学习Web Api框架的时候接触到了async/await,这个特性是.NET 4.5引入 ...

  5. 【JAVA反射机制】

    一.Class类 Java.lang.Object |-java.lang.Class<T> 构造方法:无. 常用方法: static Class<?> forName(Str ...

  6. git 常用的简单命令

    git add . 会把当前目录中所有有改动的文件(不包括.gitignore中要忽略的文件)都添加到git缓冲区以待提交 git add * 会把当前目录中所有有改动的文件(包括.gitignore ...

  7. PL/SQL Developer 9.x 注册码

    记下来,以备以后使用,好笔头,哈哈哈 Product Code:46jw8l8ymfmp2twwbuur8j9gv978m2q2du serial Number:307254 password:xs3 ...

  8. 如何在java程序中调用linux命令或者shell脚本

    转自:http://blog.sina.com.cn/s/blog_6433391301019bpn.html 在java程序中如何调用linux的命令?如何调用shell脚本呢? 这里不得不提到ja ...

  9. Ubuntu14.04LTS系统输入法的安装

    由于安装的时候选择的是英文版,所以一进入系统问题就来了:无法输入中文. 我记得自己直接选的输入法是pinyin那个 在网上看到别人到blog,直接转过来吧,只为自己收藏下,如有需要请联系原作者. 转载 ...

  10. CG&CAD resource

    Computational Geometry The Geometry Center (UIUC) Computational Geometry Pages (UIUC) Geometry in Ac ...