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[200010];
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=0;}
}a[200010];
int Search(int x){int l=x,r=n,mid,ans=n+1;while(l<=r){mid=(l+r)>>1;if(a[mid].val>a[x].val+d)ans=mid,r=mid-1;else l=mid+1;}for(int i=ans;i<=n;i++)if(!a[i].tag)return i;return n+1;
}
int main(){scanf("%d%d%d",&n,&m,&d);for(int i=1;i<=n;i++)scanf("%d",&a[i].val),a[i].id=i;Pre=1;sort(a+1,a+n+1);for(int i=1;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+1;break;}a[pre].tag=1;k++;a[pre].bel=num;while(1){Num=Search(pre);if(Num>n)break;a[Num].bel=num;a[Num].tag=1;k++;pre=Num;}}printf("%d\n",num);for(int i=1;i<=n;i++)printf("%d ",a[b[i]].bel);return 0;
}

转载于:https://www.cnblogs.com/thmyl/p/11173352.html

CF1041C Coffee Break相关推荐

  1. 蒟蒻的第一篇博客CF1041C Coffee Break(二分+贪心+set)

    CF1041C Coffee Break(二分+贪心+set) 描述 Recently Monocarp got a job. His working day lasts exactly mm min ...

  2. 【CodeForces-1041C】Coffee Break(贪心,STL,set二分维护,题意难,有坑,SJ题,构造)(知识点总结)

    题干: Recently Monocarp got a job. His working day lasts exactly mm minutes. During work, Monocarp wan ...

  3. Oracle编程入门经典 第3章 建立以及管理用户和表

    数据定义语言(DDL). 怎样建立我们自己的用户账号. 可以用于Oracle表的不同数据类型. 怎样在表上建立约束. 怎样使用数据词典获取与数据库中对象有关的信息. 3.1 数据定义语言 DDL通常用 ...

  4. ADN中国队参加微软Kinect他赢得了全国比赛三等奖,我们的创意项目与团队Kinect于Naviswork虚拟之旅...

    以下是我的英语写了一个简短的总结,直接贴出来. 让我们知道我们在这参加Hackathon That's an exciting Hackathon for me and also China team ...

  5. 100多本python书,免费电子版下载

    推荐: 1.Coffee Break Python Slicing: 24 Workouts to Master Slicing in Python, Once and for All 切片(Slic ...

  6. 《神经网络:回到未来》(Neural Nets Back to the Future)-ICML 2016

    <神经网络:回到未来>(Neural Nets Back to the Future) 官方主页:Neural Nets Back to the Future @ ICML 16 June ...

  7. figma设计_Figma与Adobe XD:我们如何选择下一个设计工具

    figma设计 The time came for changes and our design team started raising the topic again about how we s ...

  8. 日常电脑小工具编程_如何使编程成为日常习惯

    日常电脑小工具编程 Coding has been a hot topic over the last few years. A lot of people want to start program ...

  9. Installing Flex Data Services on JBoss

    Installing Flex Data Services on JBoss 出處http://weblogs.macromedia.com/dharfleet/archives/2006/07/in ...

最新文章

  1. Ceres入门——Ceres的基本使用方法
  2. css3树形图,CSS3 树形堆栈
  3. python中io.textio_Python文件读写概述(IO操作、文件读写、stringiobytesio、序列化),python,的,小,总结,StringIOBytesIO...
  4. python获取url参数 类继承_python之类的继承
  5. shell 脚本 生成文件,文件名为日期时间
  6. java缓冲输入流_java _io_字符缓冲流的输入、输出
  7. uboot——之初体验
  8. liunx下NetworkManager导致网卡不能启动
  9. 阴阳师服务器维护更新,阴阳师服务器3月10日维护更新了什么 阴阳师服务器3月10日维护更新一览...
  10. 【BZOJ 3990】 [SDOI2015]排序
  11. rhel6mysql管理_RHEL 6平台MySQL数据库服务器的安装方法
  12. Python-snap7 安装和测试
  13. Ubuntu返回上级目录快捷键
  14. 计算机房灭火器采用哪种类型,机房灭火器类型有哪些
  15. dejavu中如何添加html文件,DejaVu术语库的建立与导入.pdf
  16. 平分七筐鱼c语言y,平分七筐鱼 - 寂寞暴走伤的个人空间 - OSCHINA - 中文开源技术交流社区...
  17. 华为智慧屏“两年”,从技术创新到引领电视产业变革
  18. deepin win10字体_购机指南 | Deepin 初次体验,国产OS还有很长路要走
  19. 无法访问此网站 - DNS_PROBE_FINISHED_NXDOMAIN
  20. YUV YCbCr 区别

热门文章

  1. Column 'Column Name' does not belong to table Table
  2. 【转】完美解决Asp.Net的MasterPage中添加JavaScript路径问题
  3. python基础知识选择题-99道经典练习题助你全面掌握python基础知识,附技巧答案...
  4. python项目实例初学者-python 初学者必备14张思维导图
  5. python绘制3维图-python——绘制二元高斯分布的三维图像,
  6. python第三方库下载-3、python第三方库的安装方式
  7. 廖雪峰python教程百度云-廖雪峰Python教程的配套视频教程,全套完整版!
  8. python urllib.request 爬虫 数据处理-Python爬虫学习之(二)| urllib进阶篇
  9. python web为什么不火-编程语言里的明星:Python为什么突然不火了?
  10. python入门新手项目-新手零基础入门Python项目实战