题目传送门

 /*
题意:有 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. 解决eclipse Maven 主项目不能刷新maven

    项目->.project -> 增加<?xml version="1.0" encoding="UTF-8"?><projectD ...

  2. 列出zip文件内全部内容 当前目录下的所有文件压缩成zip格式的文件(file.zip)

    [root@ok Desktop]# zip -r image.zip ./*.jpg adding: 20161007_113743.jpg (deflated 0%) adding: 201610 ...

  3. 跳跃表Skip List的原理和实现

    >>二分查找和AVL树查找 二分查找要求元素可以随机访问,所以决定了需要把元素存储在连续内存.这样查找确实很快,但是插入和删除元素的时候,为了保证元素的有序性,就需要大量的移动元素了.如果 ...

  4. 为 ASP.NET Web API 创建帮助页面(转载)

    转载地址:http://www.asp.net/web-api/overview/creating-web-apis/creating-api-help-pages 当创建web API 时,经常要创 ...

  5. 回溯法解决N皇后问题(以四皇后为例)

    以4皇后为例,其他的N皇后问题以此类推.所谓4皇后问题就是求解如何在4×4的棋盘上无冲突的摆放4个皇后棋子.在国际象棋中,皇后的移动方式为横竖交叉的,因此在任意一个皇后所在位置的水平.竖直.以及45度 ...

  6. OCJP(1Z0-851) 模拟题分析(九)over

    Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...

  7. 几个国内速度最快的centos yum(更新源)

    转自:http://blog.itpub.net/15711267/viewspace-1068862/ 中国科技大学源 cd /etc/yum.repos.d mv CentOS-Base.repo ...

  8. hpunix下11gRac的安装

    一.检查环境 1.操作系统版本# uname -a 2.补丁包三大补丁包#swlist -l bundle|grep QPKAPPS#swlist -l bundle|grep QPKBASE#swl ...

  9. linux设备驱动概述,王明学learn

    linux设备驱动学习-1 本章节主要学习有操作系统的设备驱动和无操作系统设备驱动的区别,以及对操作系统和设备驱动关系的认识. 一.设备驱动的作用 对设备驱动最通俗的解释就是“驱使硬件设备行动” .设 ...

  10. maven项目Tomcat controller 404

    今天使用tomcat7.0.54启动现有的maven项目,可以正常启动,但是自己所写的所有的@controller注解的请求都报出了404的错误,在网上查了好久也很少找到这个问题,各种方法都尝试了也没 ...