HDU6301-2018ACM暑假多校联合训练1004-Distinct Values
题意是一个长度为n的序列,给你m组区间(l,r),在这个区间里不能填入重复的数字,同时使整个序列字典序最小
同学用的优先队列,标程里使用的是贪心同时使用set维护答案序列
贪心是先采用pre数组来确定哪些区间不能重复,再通过记录从set弹出答案的位置来计算的
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.
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4
1 2 1 2
1 2 3 1 1
- #include <iostream>
- #include <set>
- #include <algorithm>
- using namespace std;
- int pre[];
- int ret[];
- int main()
- {
- ios::sync_with_stdio(false);
- int t;
- cin >> t;
- while (t--)
- {
- set<int> s;
- int m, n;
- cin >> n >> m;
- for (int i = ; i <= n; i++)
- {
- pre[i] = i;
- s.insert(i);
- }
- for (int i = ; i <= m; i++)
- {
- int l, r;
- cin >> l >> r;
- pre[r] = min(pre[r], l);
- }
- for (int i = n - ; i > ; i--)
- pre[i] = min(pre[i], pre[i + ]);
- int pos = ;
- for (int i = ; i <= n; i++)
- {
- while (pre[i] > pos)
- {
- s.insert(ret[pos]);
- pos++;
- }
- ret[i] = *s.begin();
- s.erase(ret[i]);
- }
- for (int i = ; i <= n; i++)
- {
- cout << ret[i];
- if (i != n)
- cout << " ";
- }
- cout << endl;
- }
- return ;
- }
HDU6301-2018ACM暑假多校联合训练1004-Distinct Values的更多相关文章
- HDU6333-2018ACM暑假多校联合训练1002-Harvest of Apples-莫队+费马小定理
题意很简单啦,求S(n,m)的值 通过打表我们可以知道 S(n + 1, m) = S(n, m) * 2 - C(n, m); S(n - 1, m) = (S(n, m) + C(n - 1, m ...
- HDU6400-2018ACM暑假多校联合训练1004-Parentheses Matrix-构造
Parentheses Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- HDU6336-2018ACM暑假多校联合训练4-1005-Problem E. Matrix from Arrays-前缀和
题意是给了一种矩阵的生成方式 让你求两个左边之间的矩阵里面的数加起来的和(不是求矩阵的值) 没看标程之前硬撸写了160行 用了前缀和以后代码量缩短到原来的1/3 根据规律可以推导出这个矩阵是在不断重复 ...
- HDU6342-2018ACM暑假多校联合训练4-1011-Problem K. Expression in Memories
Problem K. Expression in Memories Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262 ...
- HDU6330-2018ACM暑假多校联合训练Problem L. Visual Cube
就是画个图啦 分三个平面去画orz #include <iostream> #include <cmath> #include <cstring> #include ...
- HDU6318-2018ACM暑假多校联合训练2-1010-Swaps and Inversions-树状数组
本题题意是,给你一个长度为n的序列,使用最少的操作把序列转换为从小到大的顺序,并输出操作数*min(x,y) 实质上是算出该序列中有多少逆序对,有归并排序和树状数组两种算法,由于数据之间的差值有点大, ...
- HDU6299-2018ACM暑假多校联合训练1002-Balanced Sequence
这个题的题意是给你n个字符串,认定()是一种平衡的串,两个以上连续的()()也是一种平衡的串,如果一对括号里面包含一个平衡的串,这个括号也被算在这个平衡的串之内, 如(()(()))是一个长度为8的平 ...
- HDU6298-2018ACM暑假多校联合训练1001-Maximum Multiple
题意大致是给你一个整数n,让你确定是否有三个正整数x,y,z既能被n整除,又能x+y+z=n,并使xyz最大 从中根据规律可以看出,只有被3或被4整除的数才能满足题目要求 被3整除的最大值为n^3/3 ...
- HDU6308-2018ACM暑假多校联合训练1011-Time Zone
题目大意就是给你UTC-8时区的时间 让你求对应时区的时间 哇 这个题 看似简单,但是一开始怎么都过不了啊 同学用自己写的read过了,后来看了一下各位大佬说改成分钟随便过,就随便过了 Problem ...
随机推荐
- Eclipse maven工程生命周期clean、compile、test、package
1.清理. 编译 工程右键->Run As->Maven build... 清理.编译操作控制台信息输出: 2.测试 同清理.编译,goals改成test 3.打包 同清理.编译,go ...
- openstack resize 更新显卡驱动程序解决问题
- Halcon学习之六:获取Image图像中Region区域的特征参数
area_center_gray ( Regions, Image : : : Area, Row, Column ) 计算Image图像中Region区域的面积Area和重心(Row,Colu ...
- Mycat实战之连续分片
1 按照日期(天)分片: 从开始日期算起,按照天数来分片 例如,从2017-11-01,每10天一个分片且可以指定结束日期 注意事项:需要提前将分片规划好,建好,否则有可能日期超出实际配置分片数 1. ...
- Hadoop IO 特性详解(1)
本文结合hadoop : the definitive guide精心而作,包含作者的心血,希望可以帮助大家理解一点hdfs的皮毛,足矣.(charles@xingbod.cn) hadoop本身自带 ...
- java5 Condition用法--实现线程间的通信
Condition的功能类似在传统线程技术中的Object.wait()和Object.natify()的功能,传统线程技术实现的互斥只能一个线程单独干,不能说这个线程干完了通知另一个线程来干,Con ...
- c语言语法目录一
1.#include<stdio.h> include 是要告诉编译器,包含一个头文件 在c语言中,任何库函数调用都需要提前包含头文件 <头文件> 代表让c语言编译器去系统目录 ...
- PHP屏蔽关键字实现方法
方法一: 思路 用正则去匹配关键字,把关键字用别的字符替换: 1 2 3 $str = "/你大爷|你麻痹|什么玩意|SB|你他妈/"; // 关键字正则字符串 $string ...
- 1-5 构建官方example-Windows平台
https://github.com/facebook/react-native https://github.com/facebook/react-native.git https://githu ...
- jsoup 的简单应用
导入相关jar包 package jsoup.zr.com.utils; import java.io.IOException; import java.util.List; import org.j ...