stl(set和map)
http://codeforces.com/gym/101911/problem/A
Recently Monocarp got a job. His working day lasts exactly m minutes. During work, Monocarp wants to drink coffee at certain moments: there are n minutes a1,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 ai
, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least d minutes pass between any two coffee breaks. Monocarp also wants to take these n 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 d
minutes pass between the end of any working day and the start of the following working day.
For each of the n
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.
Input
The first line contains three integers n
, m, d (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 n
distinct integers a1,a2,…,an (1≤ai≤m), where ai
is some minute when Monocarp wants to have a coffee break.
Output
In the first line, write the minimum number of days required to make a coffee break in each of the n
given minutes.
In the second line, print n
space separated integers. The i-th of integers should be the index of the day during which Monocarp should have a coffee break at minute ai. Days are numbered from 1
. If there are multiple optimal solutions, you may print any of them.
Examples
4 5 3
3 5 1 2
3
3 1 1 2
10 10 1
10 5 7 4 6 3 2 1 9 8
2
2 1 1 2 2 1 2 1 1 2
Note
In the first example, Monocarp can take two coffee breaks during the first day (during minutes 1
and 5, 3 minutes will pass between these breaks). One break during the second day (at minute 2), and one break during the third day (at minute 3
).
In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
题意:n个时间点,一天的时长 l(时间点都不超过l), 要求每两个时间间隔位d
输出:最少要多少天。
每个时间点在哪一天完成。。
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>;
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
typedef long long ll ;
int a[];
int ans[]; int main()
{
int n , l , b ;
while(~scanf("%d%d%d" , &n , &l , &b))
{
map<int , int>m;
set<int>s;
for(int i = ; i <= n ; i++)
{
scanf("%d" , &a[i]);
s.insert(a[i]);
m[a[i]] = i;
}
set<int>::iterator it ;
int day = ;
while(s.size() != )
{ for(int i = ; ; )
{
it = s.lower_bound(i); if(it == s.end())
{
day++ ;
break ;
}
else
{
ans[m[*it]] = day ;
s.erase(*it);
i = *it + b + ;
}
}
}
printf("%d\n" , day-);
for(int i = ; i <= n - ; i++)
{
printf("%d " , ans[i]);
}
printf("%d\n" , ans[n]);
} return ;
}
stl(set和map)的更多相关文章
- UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- STL中的map、unordered_map、hash_map
转自https://blog.csdn.net/liumou111/article/details/49252645 在之前使用STL时,经常混淆的几个数据结构,特别是做Leetcode的题目时,对于 ...
- [知识点]C++中STL容器之map
UPDATE(20190416):写完vector和set之后,发现不少内容全部引导到map上了……于是进行了一定的描述补充与更正. 零.STL目录 1.容器之map 2.容器之vector 3.容器 ...
- STL 中的map 与 hash_map的理解
可以参考侯捷编著的<STL源码剖析> STL 中的map 与 hash_map的理解 1.STL的map底层是用红黑树存储的,查找时间复杂度是log(n)级别: 2.STL的hash_ma ...
- STL中的map和unordered_map
STL中的map和unordered_map map 头文件:#include 原理:std::map的内部实现了一颗红黑树,有对其键值进行排序的功能,所以map是一个有序的容器,map中的每一个元素 ...
- Linux环境下stl库使用(map)
例子1: testMap.cpp #include <string.h> #include <iostream> #include <map> #include & ...
- stl中的map数据类型
1.1 STL map 1.1.1 背景 关联容器使用键(key)来存储访问读取元素,而顺序容器则通过元素在容器中的位置存储和访问元素. 常见的顺序容器有:vector.list.deque.stac ...
- 【STL学习】map&set
技术不只是我的工作,也是我的生活,以后的博客中会穿插一些个人的喜悦.愤怒或者感悟,希望大家能够接受. 我所有的一切,比我技术更好的怕是我的脸皮了,昨天收到京东面试没有通过的消息,喊了几句“我好悲伤啊” ...
- STL中关于map和set的四个问题?
STL map和set的使用虽不复杂,但也有一些不易理解的地方,如: 为何map和set的插入删除效率比用其他序列容器高? 或许有得人能回答出来大概原因,但要彻底明白,还需要了解STL的底层数据结构. ...
- C++标准模板库(STL)之Map
1.Map的常用用法 map:映射.可以将任何基本类型,结构体,STL容器映射到任何基本类型包括容器. 使用map,需要加map的头文件,#include<map>和using names ...
随机推荐
- Javascript 原型链之原型对象、实例和构造函数三者之间的关系
前言:用了这么久js,对于它的原型链一直有种模糊的不确切感,很不爽,隧解析之. 本文主要解决的问题有以下三个: (1)constructor 和 prototype 以及实例之间啥关系? (2)pro ...
- hr员工数据分析(实战)
hr员工数据分析项目实战 (数据已脱敏) 背景说明 某公司最近公司发生多起重要员工意外离职.部分员工工作缺乏积极性等问题,受hr部门委托,开展数据分析工作. 经与hr部门沟通,确定以下需求: 制定数据 ...
- js函数总结
最近要经常写一些Js代码,总看到同事能使用js高级函数写出比较简洁的js代码,挺羡慕的,于是就花了一些专门时间来学习. forEach.map.reduce 我就不喜欢一上来就给出语法来,先来一个例子 ...
- Centos 7 环境下安装 RabbitMQ 3.6.10
一.单机安装 在Centos7系统下部署(阿里云服务),使用yum安装 hostnamectl set-hostname rabbit01 #永久修改 1.1安装Erlang,因为RabbitMQ 是 ...
- 【技巧】Windows 10 1809无法接收1903解决方法
这都7月份了,Windows10 1903都升级的有一个月了,然而我的1809的系统一直找不到1903的更新. 虽说1903会有bug,但还是想体验一把.周围同事都更新了,心里还是痒痒的. 于是每天都 ...
- python列表转json树菜单
1.列表数据 data = [ { 'id': 1, 'parent_id': 2, 'name': "Node1" }, { 'id': 2, 'parent_id': 5, ' ...
- ps:图层知识
如果我们要改变下左图上方的蓝色小球位置,就需要先创建一个符合小球大小的选区,这并不困难,可以使用椭圆选框工具来创建一个正圆的选区(可通过[空格 CTRL 单击图像]放大图像).之后使用移动工具移动选区 ...
- jQuery ajax上传文件实例
jQuery ajax上传文件实例 <form id="form" enctype="multipart/form-data"><input ...
- 前端每日实战:37# 视频演示如何把握好 transition 和 animation 的时序,创作描边按钮特效
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/mKdzZM 可交互视频教程 此视频 ...
- Python3解leetcode Subtree of Another Tree
问题描述: Given two non-empty binary trees s and t, check whether tree t has exactly the same structure ...