codeforces 507B. Painting Pebbles 解题报告
题目链接:http://codeforces.com/problemset/problem/509/B
题目意思:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles,使得任意两个piles,用颜色c填充的pebbles数量之差 <= 1。如果不填充某种颜色,就默认数量为0。
这样说还是比较难理解吧~~~以第三组数据为例:
5 4
3 2 4 3 5
YES
1 2 3
1 3
1 2 3 4
1 3 4
1 1 2 3 4
第2个 pile 和 第5个 pile 的比较结果如下:
cha[1] = 1 (第2个pile用颜色1填充的数量是1,第5个pile为2)
cha[2] = 1 (第2个pile用颜色2填充的数量是0,第5个pile为1)
cha[3] = 0; cha[4] = 1
要想差尽可能少,就要使得颜色尽量分散。就是说,假如有个 pile 的 pebble 数目为5,可选颜色有4种,这样填就是尽量分散: 1 2 3 4 1。每个pile都这样处理,然后比较两两pile以颜色c填充的数量是否大于1,这样用vector排序比较第一个和最后一个元素之差即可。最后就输出结果了。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; const int maxn = + ;
vector<int> v[maxn], ans[maxn];
vector<int>:: iterator vp1, vp2;
int a[maxn];
int cnt[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n, k;
while (scanf("%d%d", &n, &k) != EOF) {
for (int j = ; j <= maxn; j++) {
ans[j].clear();
v[j].clear();
} for (int j = ; j < n; j++) {
scanf("%d", &a[j]);
memset(cnt, , sizeof(cnt));
for (int i = ; i < a[j]; i++) {
int tmp = ((i+) % k ? (i+) % k : k);
cnt[tmp]++;
} // 填色
for (int i = ; i <= k; i++) {
ans[i-].push_back(cnt[i]);
v[i-].push_back(cnt[i]);
}
}
bool flag = true;
for (int i = ; i < k; i++) {
sort(v[i].begin(), v[i].end());
vp1 = v[i].begin();
vp2 = v[i].end()-;
if (*vp2 - *vp1 > ) {
flag = false;
break;
}
}
if (!flag)
printf("NO\n");
else {
printf("YES\n");
for (int i = ; i < n; i++) {
for (int j = ; j < a[i]; j++) {
printf("%d ", (j+) % k ? (j+) % k : k);
}
printf("\n");
}
}
}
return ;
}
codeforces 507B. Painting Pebbles 解题报告的更多相关文章
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
- codeforces 591A. Wizards' Duel 解题报告
题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- codeforces 581C. Developing Skills 解题报告
题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...
- codeforces 577B. Modulo Sum 解题报告
题目链接:http://codeforces.com/problemset/problem/577/B 题目意思:就是给出 n 个数(a1, a2, ..., an) 和 m,问能不能从这 n 个数中 ...
- codeforces 540B.School Marks 解题报告
题目链接:http://codeforces.com/problemset/problem/540/B 题目意思:给出 k 个test的成绩,要凑剩下的 n-k个test的成绩,使得最终的n个test ...
随机推荐
- python基础教程1
python作为一种编程语言,诞生于1990年左右,算是一门比较年轻的语言(也算是90后吧),它是面向对象的,但不同于JAVA\C#那么严格要求一切皆对象,更接近于C++,是面向过程和面向对象的结合: ...
- 时间处理工具类DateUtils
public class DateUtils { public static final String SHORT_DATE ...
- Git基本常用命令
Git基本常用命令如下: mkdir: XX (创建一个空目录 XX指目录名) pwd: 显示当前目录的路径. git init 把当前的目录变成可以管理的git仓库,生成隐藏.git文件. git ...
- 遇到了IAR烧写程序出错,附解决办法The stack plug-in failed to set a breakpoint on "main"
今天做无线串口调试的时候用IAR7.51往CC2530无线模块烧程序的时候遇到了问题: 先是下载过程中有许多警告,然后就是提示无法跳断点,找不到main方法,每次烧程序都出现: The stack p ...
- 微信将推指纹支付 "指付通"会与Touch ID整合吗
有消息称微信下一版本将推指纹支付“指付通”,解决手机丢失资金安全的问题(这个应该是针对阿里手机支付的弱点),到时候用户绑定的银行卡进行付款时,不用输入密码只需在专门的支付设备(苹果Touch ID ? ...
- 读取XML文件
首先要确定好XML文件的位置,最好是放在程序的debug文件中,放在其他地方也可以,要写上绝对路径 using System; using System.Collections.Generic; us ...
- Asp.Net网页头部动态加载标题、描述、关键字、css和js文件的方法
首先head标签上添加runat="server". protected void Page_Load(object sender, EventArgs e) { Page.Tit ...
- 几个简单实用的css效果
1.要使按钮具有3D效果,只要将它的左上部分边框设置为浅色,右下部分边框设置为深色即可. eg:#button { background: #888; border: 2px solid; borde ...
- leetcode 236. Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...
- jquery版瀑布流
一个月前用jquery实现了瀑布流效果,看着当时的代码有点难过……今天抽时间稍微修改了一下.额,现在看起来不是那么难受了,就来和大家分享一下.废话不多说,开始正题~ 一.演示效果 二.html代码 & ...