CF1041C Coffee Break

题目大意:

给定nn个数和一个kk,这nn个数都不超过mm

每次从没被去掉的数里面选一个数aa,去掉aa,然后可以任意一个b(b>a+k)b(b>a+k),然后去掉任意一个c(c>b+k)c(c>b+k),以此类推

问最少能选多少个aa,然后输出每个数都是选第几个aa的时候被去掉的

输入格式:

一行三个整数n,m,k

再一行nn个整数,表示给定的数

输出格式:

第一行一个整数,表示最少选aa的个数

第二行nn个整数,表示每个数都是选第几个aa时被去掉的

题目描述

Recently Monocarp got a job. His working day lasts exactly mm minutes. During work, Monocarp wants to drink coffee at certain moments: there are nn minutes a_1, a_2, \dots, a_na1​,a2​,…,an​ , when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute).

However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute a_iai​ , Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least dd minutes pass between any two coffee breaks. Monocarp also wants to take these nn coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than dd minutes pass between the end of any working day and the start of the following working day.

For each of the nn given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.

输入输出格式

输入格式:

The first line contains three integers nn , mm , dd (1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)(1≤n≤2⋅105,n≤m≤109,1≤d≤m)— the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks.

The second line contains nn distinct integers a_1, a_2, \dots, a_na1​,a2​,…,an​ (1 \le a_i \le m)(1≤ai​≤m) , where a_iai​ is some minute when Monocarp wants to have a coffee break.

输出格式:

In the first line, write the minimum number of days required to make a coffee break in each of the nn given minutes.

In the second line, print nn space separated integers. The ii -th of integers should be the index of the day during which Monocarp should have a coffee break at minute a_iai​ . Days are numbered from 11 . If there are multiple optimal solutions, you may print any of them.

输入输出样例

输入样例#1: 复制

4 5 3
3 5 1 2
输出样例#1: 复制

3
3 1 1 2
输入样例#2: 复制

10 10 1
10 5 7 4 6 3 2 1 9 8
输出样例#2: 复制

2
2 1 1 2 2 1 2 1 1 2
/*
很显然是一个贪心,从左到右查找第一个时间点,然后以此为起点,向后尽量多的删去其他时间点
当知道a时间点时,我们要求的是满足b>a+k的最小的b,于是可以用二分查找找到b的位置,然后做标记
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int b[];
int n,m,d,k,num,pre,Pre,Num;
struct node{
int val,id,tag,bel;
bool operator < (const node w)const{
return val<w.val;
}
node(){tag=;}
}a[];
int Search(int x){
int l=x,r=n,mid,ans=n+;
while(l<=r){
mid=(l+r)>>;
if(a[mid].val>a[x].val+d)ans=mid,r=mid-;
else l=mid+;
}
for(int i=ans;i<=n;i++)
if(!a[i].tag)return i;
return n+;
}
int main(){
scanf("%d%d%d",&n,&m,&d);
for(int i=;i<=n;i++)
scanf("%d",&a[i].val),a[i].id=i;
Pre=;
sort(a+,a+n+);
for(int i=;i<=n;i++)b[a[i].id]=i;
while(k!=n){
num++;
for(int i=Pre;i<=n;i++)
if(!a[i].tag){
pre=i;Pre=pre+;
break;
}
a[pre].tag=;k++;a[pre].bel=num;
while(){
Num=Search(pre);
if(Num>n)break;
a[Num].bel=num;
a[Num].tag=;
k++;pre=Num;
}
}
printf("%d\n",num);
for(int i=;i<=n;i++)
printf("%d ",a[b[i]].bel);
return ;
}

CF1041C Coffee Break的更多相关文章

  1. Coffee Break

    题目链接:Coffee Break  Gym-101911A 题目大意:有一位员工想要利用喝咖啡来休息,他给了一个数组表示他想要喝咖啡的时间点(假设他喝咖啡用时1分钟),老板规定每次喝咖啡的时间间隔必 ...

  2. C. Coffee Break 贪心 思维 有点难 有意思

    C. Coffee Break 这个贪心之前好像写过,还是感觉挺难的,有点不会写. 这个题目大意是:给你一个数列n个元素,然后给你一天的时间,给你一个间隔时间d, 问你最少要用多少天可以把这个数列的所 ...

  3. Gym - 101911A "Coffee Break"

    传送门 题意: Monocarp得到一份工作,每天要工作 m 分钟,他有一个爱好,喜欢在休息的时候喝咖啡,但是他的老板不乐意了,就给他规定了个 时间 d,在 d 分钟内只能喝一杯咖啡. 现给出Mono ...

  4. 【CodeForces-1041C】Coffee Break(二分解决关于set,pair,upper_bound用法)

    //题意:一个的工作时间是m分钟. // 在特定的时间和咖啡 n a1,a2....an,, ai代表的是每个咖啡要在一天中对应的时间点喝掉 // 每一次喝咖啡的时间为1分钟 // 必须在一天中的ai ...

  5. A. Coffee Break(思维题,类似于邻接表的head数组用法)

    题:https://codeforces.com/gym/101911/problem/A 题意:每天工作m分钟,每次喝coffee得间隔d分钟,然后给出n个数,每个数表示想在一天中的a[i]的时刻喝 ...

  6. 2018.09.16 codeforces1041C. Coffee Break(双端队列)

    传送门 真心sb题啊. 考场上最开始看成了一道写过的原题... 仔细想了一会发现看错了. 其实就是一个sb队列. 每次插入到队首去就行了. 代码: #include<bits/stdc++.h& ...

  7. 视觉中的深度学习方法CVPR 2012 Tutorial Deep Learning Methods for Vision

    Deep Learning Methods for Vision CVPR 2012 Tutorial  9:00am-5:30pm, Sunday June 17th, Ballroom D (Fu ...

  8. javascript设计模式-工厂模式

    简单工厂模式:使用一个类来生成实例. 复杂工厂模式:使用子类来决定一个成员变量应该是哪个具体的类的实例. 简单工厂模式是由一个方法来决定到底要创建哪个类的实例, 而这些实例经常都拥有相同的接口.通过工 ...

  9. Ubuntu 13.04/12.10安装Oracle 11gR2图文教程(转)

    Ubuntu 13.04/12.10安装Oracle 11gR2图文教程 原文标题:How to Install Oracle 11G R2 Enterprise Edition Database U ...

随机推荐

  1. Idea的Http测试支持(十二)

    1. 在Tools > HTTP Client > Test RESTful Web Service 打开窗口 窗口信息如下: 2. 在Host里面填写接口请求的服务器ip地址和端口,pa ...

  2. LG4516/LOJ2546 「JSOI2018」潜入行动 树上背包

    问题描述 LG4516 LOJ2546 题解 好一个毒瘤题. hkk:JSOI的签到题 设\(opt[i][j][0/1][0/1]\)代表结点\(i\)的子树,放置\(j\)个,\(i\)放不放,\ ...

  3. 推荐一款好用到爆的开源 Java 诊断工具

    Arthas是什么鬼?Arthas是一款阿里巴巴开源的 Java 线上诊断工具,功能非常强大,可以解决很多线上不方便解决的问题. Arthas诊断使用的是命令行交互模式,支持JDK6+,Linux.M ...

  4. 瓜子IM智能客服系统的数据架构设计(整理自现场演讲)

    本文由ITPub根据封宇在[第十届中国系统架构师大会(SACC2018)]现场演讲内容整理而成. 1.引言 瓜子业务重线下,用户网上看车.预约到店.成交等许多环节都发生在线下.瓜子IM智能客服系统的目 ...

  5. MySQL数据库查询所有表名

    查找指定库中所有表名 select table_name from information_schema.tables where table_schema='db_name'; 注:替换db_nam ...

  6. 推荐 | 中文文本标注工具Chinese-Annotator(转载)

    自然语言处理的大部分任务是监督学习问题.序列标注问题如中文分词.命名实体识别,分类问题如关系识别.情感分析.意图分析等,均需要标注数据进行模型训练.深度学习大行其道的今天,基于深度学习的 NLP 模型 ...

  7. 【Java线程与内存分析工具】VisualVM与MAT简明教程

    目录 前言 VisualVM 安装与配置 本地使用 远程监控 MAT 使用场景 安装与配置 获得堆转储文件 分析堆转储文件 窥探对象内存值 堆转储文件对比分析 总结 前言 本文将简要介绍Java线程与 ...

  8. Java8接口新特性

    概述 Java 8中,你可以为接口添加静态方法和默认方法.从技术角度来说,这是完全合法的,只是它看起来违反了接口作为一个抽象定义的理念.猜想设计初衷可能使为了兼容8以下的jdk Java8出来了个函数 ...

  9. WEB-INF文件夹作用

    WEB-INF是Java的WEB应用的安全目录,客户端无法访问,只能通过服务端访问,从而实现了代码的安全.在WEB-INF中主要是系统运行的配置信息和环境 主要有classes.config.lib文 ...

  10. sequelize时间自动格式化

    问题 每次查询datetime的字段,显示出来都是这种格式 2019-08-27T12:02:05.000Z 解决办法 初始化Sequelize的时候传入dialectOptions参数 let se ...