【题目链接】: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. [BZOJ 3126] Photo

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3126 [算法] 差分约束系统 注意SPFA判负环的条件应为 : 若所有点入队次数之和 ...

  2. 快速访问GitHub

    Github网站可以访问,但是由于网络代理商的原因,造成访问速度很慢. 本文采取方法:手动更改hosts Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与 ...

  3. [Swift通天遁地]六、智能布局-(5)给视图添加Align(对齐)和Fill(填充的约束以及Label的约束

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. canvas 文字转化为粒子

    var canvas = document.createElement('canvas'); var cxt = canvas.getContext('2d'); var W = canvas.wid ...

  5. Boost(1.69.0) windows入门(译)

    目录 Boost windows入门 1. 获得Boost源代码 2. Boost源代码组织 The Boost Distribution 3. 仅用头文件的库 Header-Only Librari ...

  6. Horspool和BM算法解析

    最近算法中学到了Horspool,KMP,BM三种算法.接下来给大家做个分享. Horspool算法: 算法思路: 1.分为匹配串,原串 2.从右往左依次匹配: 一旦遇到不匹配的,原串相对于匹配串 移 ...

  7. Github提交本地版本是遇到的问题

    问题如下:*** Please tell me who you are. Run git config --global user.email "you@example.com" ...

  8. 快速学习mybatis框架

    一.介绍Mybatis(主要从以下两点进行介绍) 1.MyBatis是一个优秀的持久层框架,它对jdbc的操作数据库的过程进行封装,使开发者只需要关注 SQL 本身,而不需要花费精力去处理例如注册驱动 ...

  9. CSS3:变换和动画

    <html> <style> .container{ -webkit-perspective: 800; -webkit-perspective-origin: 50% 40% ...

  10. 顺序表查找及其优化(Java)

    顺序表查找(线性查找): private static void Ordersearch(int[] arr,int num) { for (int i = 0; i < arr.length; ...