Posterized

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

题解:每次一个访问到一个数没被放到段里时, 就在不破环前面分好段的情况下, 尽可能将这个数分到前面段里去。然后将路上的点全部分到这段里。 不要去去现在处理的这个数 的后面的区域。

如k = 10; 现在 有一个序列为 1, 11 那么 如果你每次都从头开始染长度k的话, 那么答案就是 0, 10, 但是如果你每次就染到 目前的点, 不去管这个点之后的数, 那么就会有更优的情况就是 0,2。

  

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
int a[N], to[N];
int n, m;
void ss(int u, int v){
for(int j = u; j <= v; j++){
to[j] = u;
}
}
int main(){
///Fopen;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++)
scanf("%d", &a[i]);
for(int i = ; i <= ; i++) to[i] = -;
int t;
for(int i = ; i <= n; i++){
if(to[a[i]] != -) a[i] = to[a[i]];
else {
t = a[i];
int b = a[i] - m + ;
if(b < ) b = ;
while(b < a[i]){
if(to[b] == -) break;
if(a[i]-to[b]+ > m) b++;
else break;
}
ss(b, a[i]);
a[i] = to[a[i]];
}
}
for(int i = ; i <= n; i++)
printf("%d%c", a[i], " \n"[i==n]);
return ;
}

CodeForces 980 C Posterized的更多相关文章

  1. Codeforces 980 E. The Number Games

    \(>Codeforces \space 980 E. The Number Games<\) 题目大意 : 有一棵点数为 \(n\) 的数,第 \(i\) 个点的点权是 \(2^i\) ...

  2. Codeforces 980 D. Perfect Groups

    \(>Codeforces\space980 D. Perfect Groups<\) 题目大意 : 设 \(F(S)\) 表示在集合\(S\)中把元素划分成若干组,使得每组内元素两两相乘 ...

  3. Codeforces 980 并查集/模拟贪心最小字典序 找规律/数去除完全平方因子 逆思维倍增预处理祖先标记点

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

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

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

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

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

  6. codeforces 980C Posterized

    题意: 255个像素格子,可以把这个255个分组,每组的大小不能超过k. 给出n个像素,要求每个像素用这组的key代表,并且表示出来的字典序要最小. 思路: 感谢js教本智障. 很自然的会想到贪心,也 ...

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

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

  8. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A B C D 水 模拟 二分 贪心

    A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) D - Dynamic Problem Scoring

    地址:http://codeforces.com/contest/807/problem/D 题目: D. Dynamic Problem Scoring time limit per test 2 ...

随机推荐

  1. 调用ffmpeg视频压缩工具类

    package com.example.demo; import com.alibaba.fastjson.JSONObject;import com.aliyun.oss.ClientExcepti ...

  2. http://regex.alf.nu/ 非标准答案

    Plain strings (207)                             foo Anchors (206)                                   ...

  3. RocketMQ中Broker的消息存储源码分析

    Broker和前面分析过的NameServer类似,需要在Pipeline责任链上通过NettyServerHandler来处理消息 [RocketMQ中NameServer的启动源码分析] 实际上就 ...

  4. Wpf窗口设置可拖动

    在窗口界面的一个控件(TopGrid)设置如下MouseLeftButtonDown事件即可 private void TopGrid_MouseLeftButtonDown(object sende ...

  5. RGW 学习 前言

    对于CEPH的学习已经有一段的时间了,最近的一段时间都是集中在RGW网关这一方面,所以准备将学习的过程以及源代码的分析,将以随笔的形式记录下来. 每天更新一章.

  6. macOS 安装配置yaf框架 生成yaf项目

    macOS 安装配置yaf框架 Yaf只支持PHP5.2及以上的版本. 并支持最新的PHP5.3.3 Yaf需要SPL的支持. SPL在PHP5中是默认启用的扩展模块 Yaf需要PCRE的支持. PC ...

  7. python基础之条件控制

    行与缩进 python使用缩进来表示代码块,不需要使用大括号 {} ,同一个代码块的语句必须包含相同的缩进空格数. 条件控制 #条件控制语法: if 条件: 代码块 elif 条件: 代码块 else ...

  8. 【网站公告】.NET Core 版博客站点第二次发布尝试

    在上次发布失败后,很多朋友建议我们改用 k8s ,但我们还是想再试试 docker swarm ,实在不行再改用 k8s . 在改进了 docker swarm 集群的部署后,我们准备今天 17:30 ...

  9. 史上最全面的SignalR系列教程-1、认识SignalR

    SignalR 是什么? SignalR 是一个面向 ASP.NET 开发人员的库,可简化将实时 web 功能添加到应用程序的过程. 实时 web 功能是让服务器代码将内容推送到连接的客户端立即可用, ...

  10. Why do I write a blog

    I believe the most beautiful and elegant answer to this question is from Churchill. "On a peace ...