hdu 6301 Distinct Values (双指针,水题)
大意: 给定m个区间, 求构造一个长n且字典序最小的序列, 使得每个区间内的数各不相同
求出每个位置为左端点时向右延伸最大距离, 然后双指针, 每次从set中取最小
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <string.h>
#include <queue>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std; const int N = 1e6+10;
int n, m, a[N], ans[N];
set<int> s; void work() {
scanf("%d%d", &n, &m);
REP(i,1,n) a[i]=i;
REP(i,1,m) {
int l, r;
scanf("%d%d", &l, &r);
a[l] = max(a[l], r);
}
s.clear();
REP(i,1,n) s.insert(i);
int now = 1;
REP(i,1,n) {
while (now<=a[i]) {
ans[now++]=*s.begin();
s.erase(s.begin());
}
s.insert(ans[i]);
}
REP(i,1,n) printf("%d%c",ans[i]," \n"[i==n]);
} int main() {
int t;
scanf("%d", &t);
while (t--) work();
}
hdu 6301 Distinct Values (双指针,水题)的更多相关文章
- hdu 6301 Distinct Values (思维+set)
hdu 6301 Distinct Values 题目传送门 题意: 给你m个区间,让你求出一个长度为n的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...
- hdu 6301 Distinct Values (2018 Multi-University Training Contest 1 1004)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 6301 Distinct Values (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 6301 Distinct Values
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6301 多校contest1 题目大意是有一个长度为N的数组,给出M个"事实",每个 ...
- hdu 6301 Distinct Values(贪心)题解
题意:长为n的串,给你m个区间,这些区间内元素不重复,问这样的串字典序最小为? 思路:用set保存当前能插入的元素,这样就能直接插入最小元素了.对操作按l排序,因为排过的不用排,所以两个指针L,R是一 ...
- HDU 5578 Friendship of Frog 水题
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 5590 ZYB's Biology 水题
ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...
- HDU 5538 L - House Building 水题
L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 6301.Distinct Values-贪心、构造字典序最小的数列 (2018 Multi-University Training Contest 1 1004)
HDU6301.Distinct Values 这个题就是给你区间要求区间内的数都不相同,然后要求是字典序最小,直接贪心走一遍,但是自己写的时候,思路没有错,初始化写挫了... 将区间按左端点小的排序 ...
随机推荐
- Oracle之归档模式与非归档模式
归档模式和非归档模式 在DBA部署数据库之初,必须要做出的最重要决定之一就是选择归档模式(ARCHIVELOG)或者非 归档模式(NOARCHIVELOG )下运行数据库.我们知道,Oracle 数据 ...
- CodeForeces 25E (kmp)
E. Test time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputst ...
- 服务器和客户端的交互方式(Socket,http协议)和各自特点适用范围
1 数据传输方式 1.1 Socket传输的定义和其特点 所谓socket通常也称作"套接字",实现服务器和客户端之间的物理连接,并进行数据传输,主要有UDP和TCP两个协议.S ...
- Python开发【模块】:Pygal 绘制直方图
Pygal Pygal可用来生成可缩放的矢量图形文件,对于需要在尺寸不同的屏幕上显示的图表,这很有用,可以自动缩放,自适应观看者的屏幕 1.Pygal模块安装 ① Windows系统 # Pygal模 ...
- android 模仿今日头条ViewPager+TabLayout
导入依赖库: compile 'com.android.support:design:25.3.1' 1.fg_content_demo2.xml <?xml version="1.0 ...
- 美图秀秀DBA谈MySQL运维及优化
美图秀秀DBA谈MySQL运维及优化 https://mp.weixin.qq.com/s?__biz=MzI4NTA1MDEwNg==&mid=401797597&idx=2& ...
- MR的shuffle和Spark的shuffle之间的区别
mr的shuffle mapShuffle 数据存到hdfs中是以块进行存储的,每一个块对应一个分片,maptask就是从分片中获取数据的 在某个节点上启动了map Task,map Task读取是通 ...
- Django Rest Framework(3)-----APIView与Viewsets
REST framework提供了一个APIView类,它是Django的View类的子类. REST framework主要的几种view以及他们之间的关系: mixins 到目前为止,我们使用的创 ...
- 命令行下开启与关闭windows防火墙关端口(转)
sc config sharedaccess start= auto //设置防火墙服务为自动 net start sharedaccess //开启防火墙服务 关闭端口 netsh firewall ...
- 转:CentOS设置程序开机自启动的方法
转自:http://www.centos.bz/2011/09/centos-setup-process-startup-boot/ 1.把启动程序的命令添加到/etc/rc.d/rc.local文件 ...