【题目链接】: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. Polymorphism (C# Programming Guide)

    https://msdn.microsoft.com/en-us/library/ms173152.aspx Polymorphism is often referred to as the thir ...

  2. Web Tab, Project Properties

    https://msdn.microsoft.com/en-us/library/aa983445(v=vs.100).aspx The Web tab of the project Properti ...

  3. python库学习笔记——Pandas数据索引:ix、loc、iloc区别

    Different Choices for Indexing 1. loc--通过行标签索引行数据 1.1 loc[1]表示索引的是第1行(index 是整数) import pandas as pd ...

  4. bzoj3629 [JLOI2014]聪明的燕姿——DFS+约数和定理

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3629 扫除了一个知识盲点:约数和定理 约数和定理: 对于一个大于1正整数n可以分解质因数:n ...

  5. 懒人学习automake, Makefile.am,configure.ac

    已经存在Makefile.am,如何生成Makefile? 步骤: [root@localhost hello]# autoscan .///在当前文件夹中搜索 [root@localhost hel ...

  6. 利用【监听器】动态加载Log4j配置文件

    转自:https://veromca273.iteye.com/blog/1889304 1 创建监听器: public class LogListener implements ServletCon ...

  7. Gym - 100162G 2012-2013 Petrozavodsk Winter Training Camp G. Lyndon Words 暴力枚举

    题面 题意:如果一个字符串的最小表示法是他自己,他就是一个Lyndon Word. 例如  aabcb 他的循环串有 abcba  bcbaa cbaab baabc 其中字典序最小的是他自己 现在给 ...

  8. 通过类库ChineseChar实现将汉字转化为拼音

    //封装dllusing Microsoft.International.Converters.PinYinConverter;using System.Text;namespace Utils{ p ...

  9. ACM_黑色星期五

    黑色星期五 Time Limit: 2000/1000ms (Java/Others) Problem Description: 13号又是星期五是一个不寻常的日子吗?13号在星期五比在其他日少吗?为 ...

  10. synchronized关键字详解(二)

    synchronized关键字的性质 1.可重入:同一线程的外层函数获得锁之后,内层函数可直接再次获得该锁,好处:避免死锁,提升封装性 证明可重入粒度:1.同一个方法是可重入的 2.可重入不要求是同一 ...