Distinct Values(贪心)
问题 D: Distinct Values
时间限制: 1 Sec 内存限制: 128 MB
提交: 13 解决: 5
[提交] [状态] [讨论版] [命题人:admin]
题目描述
Chiaki would like to find a lexicographically minimal array which meets the facts.
输入
The first line contains two integers n and m (1≤n,m≤105) -- the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (1≤li≤ri≤n).
It is guaranteed that neither the sum of all n nor the sum of all m exceeds 106.
输出
样例输入
3
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4
样例输出
1 2
1 2 1 2
1 2 3 1 1
思路:把一个区间的端点中值较大的一个放在前面,向后压倒! 详见代码:
AC代码:
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
priority_queue<int,vector<int>,greater<int> > store;
int t,n,m,l,r,a[];
int main()
{
scanf("%d",&t);
while(t--)
{
ans.clear();
while(!store.empty()) store.pop();
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
{
a[i]=i;
store.push(i);
}
while(m--)
{
scanf("%d %d",&l,&r);
a[l]=max(a[l],r);
}
int cnt=,now=;
for(int i=;i<=n;i++)
{
if(a[i]<now) continue;
while(now>a[cnt+] && cnt+<now)
{
store.push(ans[cnt]);
cnt++;
}
while(now<=a[i])
{
ans.push_back(store.top());
store.pop();
now++;
}
}
for(int i=;i<ans.size();i++)
{
if(i==) printf("%d",ans[i]);
else printf(" %d",ans[i]);
}
printf("\n");
}
return ;
}
Distinct Values(贪心)的更多相关文章
- 2018 Multi-University Training Contest 1 Distinct Values 【贪心 + set】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6301 Distinct Values Time Limit: 4000/2000 MS (Java/Ot ...
- hdu 6301 Distinct Values (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU6301 Distinct Values (多校第一场1004) (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 杭电2018暑假多校第一场 D Distinct Values hdu6301 贪心
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu多校1004 Distinct Values
Distinct Values Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): ...
- 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 多校对抗赛 D Distinct Values
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 6301 Distinct Values (思维+set)
hdu 6301 Distinct Values 题目传送门 题意: 给你m个区间,让你求出一个长度为n的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...
- hdu 6301 Distinct Values(贪心)题解
题意:长为n的串,给你m个区间,这些区间内元素不重复,问这样的串字典序最小为? 思路:用set保存当前能插入的元素,这样就能直接插入最小元素了.对操作按l排序,因为排过的不用排,所以两个指针L,R是一 ...
随机推荐
- ue4 射线Trace Responses(踪迹响应)
关于 Visibility和Camera区别 就是两个预定义通道 可以通过Character和pawn的Collider设置看出为什么要有这两个的区别,预制值设置成Pawn也是跟下图一致 所以Visi ...
- 51nod1282(最小表示法&&枚举)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1282 题意:中文题目诶- 思路:指针不可转,刻盘可转,显然,对 ...
- MFS安装
mfs github地址:https://github.com/moosefs/moosefs 一. 准备 1. 名字解释 Mfsmaster 元数据 Metalogger 元数据备份,用于恢复数据( ...
- glassfish 自定义 jaas realm
https://www.oschina.net/translate/custom-jaas-realm-for-glassfish-3
- tinkphp5使用中碰到的问题 持续更新
1.使用助手函数(如controller(),model(),validate())进行实例化时只需要引入think\Controller或think\Model或think\Validate即可,无 ...
- ZROI WC Round1 题解
ZROI WC Round1 题解 Problem A 题意 一个 \(n \times m\) 格子图,一个人从左上角出发,每次向右或者向下走一格,方法如下: 如果他在最下面一排,那么他会往右行走. ...
- PKUSC 2018 题解
PKUSC 2018 题解 Day 1 T1 真实排名 Link Solution 考虑对于每一个人单独算 每一个人有两种情况,翻倍和不翻倍,他的名次不变等价于大于等于他的人数不变 设当前考虑的人的成 ...
- hdu1175-连连看(dfs)
一个一个走,记录方向改变了几次,不能超过两次,两次如果还没到终点return: #include<cstdio> #include<string.h> #define inf ...
- Zepto事件模块源码分析
Zepto事件模块源码分析 一.保存事件数据的handlers 我们知道js原生api中要移除事件,需要传入绑定时的回调函数.而Zepto则可以不传入回调函数,直接移除对应类型的所有事件.原因就在于Z ...
- .md文件插图片,不建议使用绝对地址。
一 主要有两种方法,一种绝对地址,一种相对地址. 而百度的话,全都是说绝对地址的. 但是,有很大的弊端啊 orz 二 先说绝对地址 ![image](https://github.com/AngelS ...