题意:

255个像素格子,可以把这个255个分组,每组的大小不能超过k。

给出n个像素,要求每个像素用这组的key代表,并且表示出来的字典序要最小。

思路:

感谢js教本智障。

很自然的会想到贪心,也就是说,每次对当前的数,都要找到最小的可以当它的key的数。

那么这种数只能有两种情况,一种是这个数还没有使用过,另一种就是这个数是自己的key,其它情况都不满足。

比如

4 3
2 14 3 4

2找到0,然后把0到2的key都变为0;

找3的时候,由于1,2已经被使用,所以3只能找到自己。

代码:

 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for (int i = ;i < ;i++) a[i] = -;
while (n--)
{
int x;
scanf("%d",&x);
if (a[x] == -)
{
for (int i = max(,x-k+);i <= x;i++)
{
if (a[i] == - || a[i] == i)
{
for (int j = i;j <= x;j++) a[j] = i;
break;
}
}
}
printf("%d ",a[x]);
}
return ;
}

codeforces 980C Posterized的更多相关文章

  1. Codeforces Round #480 (Div. 2)980C Posterized+分组类贪心

    传送门:http://codeforces.com/contest/980/problem/C 参考 题意:给定n个数字,每个数在0~256间,现在给至多连续k的数分为一组,给出字典序最小的答案. 思 ...

  2. Codeforces Round #480 (Div. 2) C - Posterized

    题目地址:http://codeforces.com/contest/980/problem/C 官方题解: 题解:一共256个像素网格,可以把这个256个分组,每个分组大小<=k.给出n个像素 ...

  3. CodeForces 980 C Posterized

    Posterized 题意:将[0,255] 分成 若干段, 每一段的长度最多为k, 每一个数只能被放进一个段里, 然后每一段的数组都可以被这一段最小的数字表示, 求最小的字典序. 题解:每次一个访问 ...

  4. 【贪心】Codeforces Round #480 (Div. 2) C. Posterized

    题意:让你对[0,255]这个序列任意划分成一些不重叠的子段,每个子段的大小不超过K.给你n个不超过255的数,让你将每个数替换成它所在子段的任意一个元素,使得最终这个n个数的序列的字典序最小. p[ ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. Flask需要登录权限的装饰器写法

    def wapper(func): def inner(*args,**kwargs): if not request.cookies.get("username"): retur ...

  2. git 用远程覆盖本地

    git fetch --all git reset --hard origin/master

  3. 【PyQt5-Qt Designer】按钮系列

    [PyQt5-Qt Designer]按钮系列 复选框(QCheckBox) 效果如下: 参考: https://zhuanlan.zhihu.com/p/30509947 完整代码: from Py ...

  4. CSS 优先级&伪元素&伪类

    优先级 单冒号(:)用于CSS3伪类,双冒号(::)用于CSS3伪元素 伪元素 属性 描述 CSS :first-letter 向文本的第一个字母添加特殊样式 1 :first-line 向文本的首行 ...

  5. JavaScript学习(一)

    变量本身是没有类型的,类型在于它的值(注意开头都是小写).

  6. linux 查看系统负载:uptime

    uptime命令用于查看系统负载,跟 w 命令的输出内容一致 [root@mysql ~]# uptime :: up days, :, user, load average: 1.12, 0.97, ...

  7. MongoDB与关系型数据库 区别

    mysql  mongodb 表     table    Collection 字段  Colum   Fields 行 row Document Mongo中的一些概念 ------------- ...

  8. 最少步数(bfs)

    最少步数 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 这有一个迷宫,有0~8行和0~8列: 1,1,1,1,1,1,1,1,1 1,0,0,1,0,0,1,0,1 ...

  9. emq共享订阅

    emqtt 试用(二)验证 emq 和 mosquito 的共享订阅 1. 多个订阅者都订阅以下主题形式 clientA 订阅  $queue/topic 发布主题名称为 topic1   clien ...

  10. 【LeetCode每天一题】Longest Substring Without Repeating Characters(最长无重复的字串)

    Given a string, find the length of the longest substring without repeating characters. Example 1:    ...