【题目链接】:http://codeforces.com/contest/509/problem/B

【题意】



给n鹅卵石染色;

有k种颜色可供选择;

问你有没有染色方案;

使得各个堆的鹅卵石里面,第i颜色的鹅卵石的数目的差的绝对值都不大于1

【题解】



把所有的堆

一开始按照石头的数目升序排一遍;

然后顺序处理

对于第一堆石头

1..k,1..k一直重复直到满a[1]个石头;

这以后

每一行直接复制前一行的;

然后开始给多出来的石头染色;

就给他们染成能够染的石子就好;

一开始1..k都还能再染一个;

所以如果∑a[i]-a[i-1]>k的话就无解

否则肯定有解的;

每次比上一层多a[i]-a[i-1]个石子就好(选择可以染的颜色);

模拟



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110; struct abc
{
int id,val;
}; int n,k,ma[N],ans[N][N],rest[N];
abc a[N]; bool cmp1(abc a,abc b)
{
return a.val<b.val;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
rei(n),rei(k);
rep1(i,1,n)
rei(a[i].val),a[i].id = i;
rep1(i,1,k)
rest[i] = 1;
sort(a+1,a+1+n,cmp1);
int now = 0;
rep1(i,1,a[1].val)
{
now++;
if (now>k) now = 1;
ans[a[1].id][i] = now;
}
rep1(i,2,n)
{
rep1(j,1,a[i-1].val)
ans[a[i].id][j] = ans[a[i-1].id][j];
int need = a[i].val-a[i-1].val;
int now = 1;
if (need)
rep1(j,1,k)
if (rest[j])
{
rest[j]=0;
ans[a[i].id][a[i-1].val+now] = j;
need--;now++;
if (!need) break;
}
if (need) return pri("NO"<<endl),0;
}
pri("YES"<<endl);
rep1(i,1,n)
{
for (int j = 1;;j++)
{
if (ans[i][j]==0) break;
pri(ans[i][j]<<' ');
}
pri(endl);
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 509B】Painting Pebbles的更多相关文章

  1. 【Codeforces 1132C】Painting the Fence

    Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数量. 思路:首先枚举第一个删掉的区间,然后我们可以通过差分来求出每个格子被 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 789A】Anastasia and pebbles

    [题目链接]:http://codeforces.com/contest/789/problem/A [题意] 有n种物品,每种物品有wi个; 你有两个口袋,每个口袋最多装k个物品; 且口袋里面只能装 ...

  4. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. openStack aio nova service-list neutron ext-list

  2. shell脚本-高级变量

    shell脚本-高级变量 字符串变量切片 ${#var}: 返回字符串变量var的长度 ${var:offset}: 返回字符串变量var中从第offset个字符后(不包括第offset 个字符)的字 ...

  3. 湖南集训day5

    难度:☆☆☆☆☆☆☆ /* 二分答案 算斜率算截距巴拉巴拉很好推的公式 貌似没这么麻烦我太弱了...... 唉不重要... */ #include<iostream> #include&l ...

  4. 题解报告:hdu 1162 Eddy's picture

    Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...

  5. SVN系列学习(二)-小乌龟的安装与配置

    1.TortoiseSVN的介绍 TortoiseSVN是Subversion版本控制系统的一个免费开源客户端,可以超越时间的管理文件和目录. 2.TortoiseSVN的安装 下载地址:http:/ ...

  6. python认识标识符

    #python标识符 Python在编程的时候,起的名字就叫做标识符,其中变量和常量就是标识符的一种 #命名原则 在python中标识符的命名是有规则的,按正确命名规则命名的可以使用的标示符叫做有效标 ...

  7. JS——高级各行换色

    1.获取tbody下的子元素 2.注册鼠标覆盖事件时存储当时的背景颜色,注册鼠标离开事件时把存储的颜色赋值注册事件对象 <!DOCTYPE html> <html> <h ...

  8. 易语言 打开exe可执行文件、打开网页

    打开文件--------按钮被单击事件 直接复制以下代码即可 .版本 2 .子程序 _按钮58_被单击 运行 (“exe文件路径”, 假, ) 打开网站--------按钮被单击事件 直接复制以下代码 ...

  9. 基于证书的MS SQL2005数据库镜像搭建

    一.准备工作: 3台服务器同版本,硬盘分区大小相同,安装相同版本数据库软件. host中分别标注3台服务器IP和主机名称. 主体服务器上创建数据库,并进行完整备份数据库和数据库事务. 拷贝备份文件给镜 ...

  10. 12、scala函数式编程集合

    1.Scala的集合体系结构 2.List 3.LikedList 4.Set 5.集合的函数式编程 6.函数式编程综合案例:统计单词总数 1.Scala的集合体系结构 Scala中集合体系主要包括: ...