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. Flink 源码解析 —— 如何获取 ExecutionGraph ?

    https://t.zsxq.com/UnA2jIi 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1学习 -- Mac 上搭建 Flink 1.6. ...

  2. alluxio源码解析-netty部分(2)

    netty简介 Netty是 一个异步事件驱动的网络应用程序框架,用于快速开发可维护的高性能协议服务器和客户端.   netty作为alluxio中重要的通讯组件 在常见的客户端上传,下载中,都会有n ...

  3. Codeforces 343D Water Tree

    题意简述 维护一棵树,支持以下操作: 0 v:将以v为跟的子树赋值为1 1 v:将v到根节点的路径赋值为0 2 v:询问v的值 题解思路 树剖+珂朵莉树 代码 #include <set> ...

  4. 6.PHP操作MySQL的步骤

    第一步:PHP连接MySQL服务器 第三步:设置MySQL请求或返回数据的字符集 第四步:执行各种SQL语句 l 查询SQL语句:mysql_query(“SELECT * FROM 007_news ...

  5. Yii GridView Ajax 刷新

    Yii GridView  Ajax 刷新,当页面点击一个按钮时,刷新数据. 1.控制器 <?php class privController extends Controller{ publi ...

  6. Mybatis中使用PageHelper插件进行分页

    分页的场景比较常见,下面主要介绍一下使用PageHelper插件进行分页操作: 一.概述: PageHelper支持对mybatis进行分页操作,项目在github地址: https://github ...

  7. Go---go-cache包学习

    github.com/patrickmn/go-cachego-cache是一款类似于memached 的key/value 缓存软件.它比较适用于单机执行的应用程序.go-cache实质上就是拥有过 ...

  8. nginx之gzip压缩提升网站速度

    目录: 为啥使用gzip压缩 nginx使用gzip gzip的常用配置参数 nginx配置gzip 注意 为啥使用gzip压缩 开启nginx的gzip压缩,网页中的js,css等静态资源的大小会大 ...

  9. mybatis逆向工程maven版本idea工具

    基于springboot2版本 pom基本依赖 <parent> <groupId>org.springframework.boot</groupId> <a ...

  10. HBase 系列(六)——HBase Java API 的基本使用

    一.简述 截至到目前 (2019.04),HBase 有两个主要的版本,分别是 1.x 和 2.x ,两个版本的 Java API 有所不同,1.x 中某些方法在 2.x 中被标识为 @depreca ...