【题目链接】: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. 【POJ 1328】 Radar Installation

    [题目链接] http://poj.org/problem?id=1328 [算法] 每个雷达都位于笛卡尔坐标系的x轴上,因此,对于每个岛屿,我们都可以用勾股定理算出它的有效管辖区域 那么,问题就被转 ...

  2. [luogu_U15116]珈百璃堕落的开始

    https://www.zybuluo.com/ysner/note/1239458 题面 给定\(n\)个二元组\((x,y)\),问有多少种方案,使得选出其中几个后,\(\sum x=\sum y ...

  3. 04、抽取BaseActivity

    // 在使用SDK各组件之前初始化context信息,传入ApplicationContext // 注意该方法要再setContentView方法之前实现 // SDKInitializer.ini ...

  4. 图练习-BFS-从起点到目标点的最短步数

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2830 简单bfs #include <s ...

  5. C. Searching for Graph(cf)

    C. Searching for Graph time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. StreamingListener技术点

    以下是对StreamingListene的研究,由于比较简单,故只贴代码,不做解释 /** * Created by gabry.wu on 2016/5/27. * 实现StreamingListe ...

  7. Eclipse设置空格代替tab

    1.点击 window->preference-,依次选择 General->Editors->Text Editors,选中右侧的 insert space for tabs;如下 ...

  8. [转]mysql视图学习总结

    转自:http://www.cnblogs.com/wangtao_20/archive/2011/02/24/1964276.html 一.使用视图的理由是什么?1.安全性.一般是这样做的:创建一个 ...

  9. [转]Linux命令wc的详细用法

    转自:http://blog.hehehehehe.cn/a/17301.htm wc命令用来打印文件的文本行数.单词数.字节数等(print the number of newlines, word ...

  10. DataFrame编程模型初谈与Spark SQL

    Spark SQL在Spark内核基础上提供了对结构化数据的处理,在Spark1.3版本中,Spark SQL不仅可以作为分布式的SQL查询引擎,还引入了新的DataFrame编程模型. 在Spark ...