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 这个题就是给你区间要求区间内的数都不相同,然后要求是字典序最小,直接贪心走一遍,但是自己写的时候,思路没有错,初始化写挫了... 将区间按左端点小的排序 ...
随机推荐
- 170518、FastDFS_配置文件详解
http://bbs.chinaunix.net/thread-1941456-1-1.html 首先是 tracker.conf # is this config file disabled # f ...
- js jquery.pagination.js分页
1.使用插件为 jquery.pagination.js ,如果没有这个js文件的话,我可以给发个. 首先引用 jquery.pagination.js (分页js),跟pagination.css( ...
- 为什么不要使用"using namespace XXX"
为什么不要使用"using namespace XXX" 1.避免降低性能 2.避免Entity冲突 This is not related to performance at a ...
- JSONUtil(JAVA对象/List与json互转,xml与json互转)
package com.chauvet.utils.json; import java.io.BufferedReader; import java.io.File; import java.io.F ...
- freemarker 判断写法
1.if条件写法:如果data非空则输出:test<#if data?? >test</#if> 2.为空则输出 <#if !(data??) > test < ...
- 【mlflow】mlflow打包、启动、换用mysql backend、mysql配置
mlflow是一个自动化机器学习平台,支持python2也支持python3 mlflow9.0添加了数据库作为tracking data的存储: https://github.com/mlflow/ ...
- thinkcmf安装教程与目录结构详解 快速上手版
最近接了一个建站项目,要求用thinkcmf来搭建,ytkah在想php都大致一样吧,快速地下载安装包,可是!怎么安装呢?没看到安装指引文件或目录,查看了安装说明public目录做为网站根目录,入口文 ...
- loadrunner11的移动端性能测试之结果分析
测试步骤之结果分析器(Analysis) 进入Analysis 当场景停止运行后,可从Controller中进入.点击[Results]—[Analysis Results]见下图: 若想打开一个已保 ...
- SVM引入拉格朗日乘子[转载]
转自:https://zhidao.baidu.com/question/494249074914968332.html SVM使用拉格朗日乘子法更为高效地求解了优化问题. SVM将寻找具有最大几何间 ...
- libgomp-4.8.5-28.el7_5.1.x86_64 is a duplicate with libgomp-4.8.5-4.el7.x86_64
列出重复的包 # package-cleanup --dupes 删除重复的包 # package-cleanup --cleandupes