Posterized
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter.

Their algorithm will be tested on an array of integers, where the ii-th integer represents the color of the ii-th pixel in the image. The image is in black and white, therefore the color of each pixel will be an integer between 0 and 255 (inclusive).

To implement the filter, students are required to divide the black and white color range [0, 255] into groups of consecutive colors, and select one color in each group to be the group’s key. In order to preserve image details, the size of a group must not be greater than kk, and each color should belong to exactly one group.

Finally, the students will replace the color of each pixel in the array with that color’s assigned group key.

To better understand the effect, here is an image of a basking turtle where the Posterization Filter was applied with increasing kk to the right.

To make the process of checking the final answer easier, Professor Ibrahim wants students to divide the groups and assign the keys in a way that produces the lexicographically smallest possible array.

Input

The first line of input contains two integers nn and kk (1≤n≤1051≤n≤105, 1≤k≤2561≤k≤256), the number of pixels in the image, and the maximum size of a group, respectively.

The second line contains nn integers p1,p2,…,pnp1,p2,…,pn (0≤pi≤2550≤pi≤255), where pipi is the color of the ii-th pixel.

Output

Print nn space-separated integers; the lexicographically smallest possible array that represents the image after applying the Posterization filter.

Examples
input

Copy
4 3
2 14 3 4
output

Copy
0 12 3 3
input

Copy
5 2
0 2 1 255 254
output

Copy
0 1 1 254 254
Note

One possible way to group colors and assign keys for the first sample:

Color 22 belongs to the group [0,2][0,2], with group key 00.

Color 1414 belongs to the group [12,14][12,14], with group key 1212.

Colors 33 and 44 belong to group [3,5][3,5], with group key 33.

Other groups won't affect the result so they are not listed here.

 题意: 给你n个数,每个数的key为这个所在的组别key,每组数的大小不大于k,求使最后key值组成的序列字典序最小的一组key值
 
 题解: 直接贪心,枚举每个数的前面的数,用没有被用过的最早的数做key值,就是字典序最小了
 
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e5 + ;
const int mod = 1e9 + ;
typedef long long ll;
ll x, n, m, vis[maxn], a[maxn];
int main(){
std::ios::sync_with_stdio(false);
cin >> n >> m;
memset( vis, -, sizeof(vis) );
for( ll i = ; i < n; i ++ ) {
cin >> x;
if( vis[x] == - ) {
for( ll j = max( (ll), x-m+ ); j <= x; j ++ ) {
if( vis[j] == - || vis[j] == j ) {
for( ll k = j; k <= x; k ++ ) {
vis[k] = j;
}
}
}
}
a[i] = vis[x];
}
for( ll i = ; i < n; i ++ ) {
if( i == n- ) {
cout << a[i] << endl;
} else {
cout << a[i] << " ";
}
}
return ;
}

CF980C Posterized 贪心 二十五的更多相关文章

  1. Bootstrap <基础二十五>警告(Alerts)

    警告(Alerts)以及 Bootstrap 所提供的用于警告的 class.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添加一个 ...

  2. VMware vSphere 服务器虚拟化之二十五 桌面虚拟化之终端服务池

    VMware vSphere 服务器虚拟化之二十五 桌面虚拟化之终端服务池 终端服务池是指由一台或多台微软终端服务器提供服务的桌面源组成的池.终端服务器桌面源可交付多个桌面.它具有以下特征: 1.终端 ...

  3. WCF技术剖析之二十五: 元数据(Metadata)架构体系全景展现[元数据描述篇]

    原文:WCF技术剖析之二十五: 元数据(Metadata)架构体系全景展现[元数据描述篇] 在[WS标准篇]中我花了很大的篇幅介绍了WS-MEX以及与它相关的WS规范:WS-Policy.WS-Tra ...

  4. Bootstrap入门(二十五)JS插件2:过渡效果

    Bootstrap入门(二十五)JS插件2:过渡效果 对于简单的过渡效果,只需将 transition.js 和其它 JS 文件一起引入即可.如果你使用的是编译(或压缩)版的bootstrap.js  ...

  5. JAVA基础再回首(二十五)——Lock锁的使用、死锁问题、多线程生产者和消费者、线程池、匿名内部类使用多线程、定时器、面试题

    JAVA基础再回首(二十五)--Lock锁的使用.死锁问题.多线程生产者和消费者.线程池.匿名内部类使用多线程.定时器.面试题 版权声明:转载必须注明本文转自程序猿杜鹏程的博客:http://blog ...

  6. JAVA之旅(二十五)——文件复制,字符流的缓冲区,BufferedWriter,BufferedReader,通过缓冲区复制文件,readLine工作原理,自定义readLine

    JAVA之旅(二十五)--文件复制,字符流的缓冲区,BufferedWriter,BufferedReader,通过缓冲区复制文件,readLine工作原理,自定义readLine 我们继续IO上个篇 ...

  7. Java进阶(二十五)Java连接mysql数据库(底层实现)

    Java进阶(二十五)Java连接mysql数据库(底层实现) 前言 很长时间没有系统的使用java做项目了.现在需要使用java完成一个实验,其中涉及到java连接数据库.让自己来写,记忆中已无从搜 ...

  8. 策略模式 Strategy 政策Policy 行为型 设计模式(二十五)

    策略模式 Strategy   与策略相关的常见词汇有:营销策略.折扣策略.教学策略.记忆策略.学习策略.... “策略”意味着分情况讨论,而不是一概而论 面对不同年龄段的人,面对不同的商品,必然将会 ...

  9. 二十五. Python基础(25)--模块和包

    二十五. Python基础(25)--模块和包 ● 知识框架   ● 模块的属性__name__ # my_module.py   def fun1():     print("Hello& ...

随机推荐

  1. Django REST framework的使用简单介绍

    官方文档:https://www.django-rest-framework.org/ GitHub源码:https://github.com/encode/django-rest-framework ...

  2. CountDownLatch实现多线程并发请求

    package com.test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Dat ...

  3. C# 10分钟完成百度语音技术(语音识别与合成)——入门篇

    我们已经讲了人脸识别(入门+进阶).图片识别(入门).下面是链接: C# 10分钟完成百度人脸识别——入门篇 C# 30分钟完成百度人脸识别——进阶篇(文末附源码) C# 10分钟完成百度图片提取文字 ...

  4. Redis批量删除key的小技巧,你知道吗?

    在使用redis的过程中,经常会遇到要批量删除某种规则的key,但是redis提供了批量查询一类key的命令keys或scan,没有提供批量删除某种规则key的命令,怎么办?看完本文即可,哈哈. 本文 ...

  5. [转载]关于ActiveMQ集群

    转载于 http://blog.csdn.net/nimmy/article/details/6247289 近日因工作关系,在研究JMS,使用ActiveMQ作为提供者,考虑到消息的重要,拟采用Ac ...

  6. .Net Core 最优 MD5 打开方式!初学者建议收藏(支持 SHA1,SHA256,.Net Framework)

    public static string GetMd5Hash(string input) { using (MD5 md5Hash = MD5.Create()) { // Convert the ...

  7. hadoop2.7之作业提交详解(上)

    根据wordcount进行分析: import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; impo ...

  8. ubuntu16.04双系统创建分区

    ubuntu安装分区 安装ubuntu 图1:Ubuntu Linux分区向导 如果希望对分区过程进行完全控制,可以使用"其它"选项.单击"继续"按钮,安装向导 ...

  9. 分布式系统的一致性级别划分及Zookeeper一致性级别分析

    最近在研究分布式系统的一些理论概念,例如关于分布式系统一致性的讨论,看了一些文章我有一些不解.大多数对分布式系统一致性的划分是将其分为三类:强一致性,顺序一致性以及弱一致性.强一致性(Strict C ...

  10. Redis 学习笔记(篇九):主从复制

    Redis 中,可以通过执行 savleof 命令或者设置 slaveof 选项,让一个服务器去复制另一个服务器,我们称被复制的服务器为主服务器,而对主服务器进行复制的服务器则被称为从服务器. Red ...