codeforces 496 E. Distributing Parts(贪心+set二分)
题目链接:http://codeforces.com/contest/496/problem/E
题意:有n场演出,每场演出都有限制的高音和低音。然后m个人给出每个人的极限高音和低音还有出场次数。
最后问能否将每场演出都安排人,最后输出每场演出的出赛人编号,有多种情况就任意输出。
思路挺简单的就将演出和人都按照低音的从小到大拍好序,然后便利演出。将每场演出能符合条件的人数放入set里
然后二分查找最小高音能符合的。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
const int M = 1e5 + 10;
struct TnT {
int l , r , num , pos;
}song[M] , person[M] , gg[M];
bool cmp(TnT a , TnT b) {
return a.l < b.l;
}
int ans[M];
set<pair<int , int>> se;
int main() {
int n , m;
scanf("%d" , &n);
for(int i = 1 ; i <= n ; i++) {
scanf("%d%d" , &song[i].l , &song[i].r);
song[i].pos = i , ans[i + 1] = 0;
}
scanf("%d" , &m);
for(int i = 1 ; i <= m ; i++) {
scanf("%d%d%d" , &person[i].l , &person[i].r , &person[i].num);
person[i].pos = i;
gg[i].num = person[i].num;
}
sort(song + 1 , song + n + 1 , cmp);
sort(person + 1 , person + m + 1 , cmp);
int temp = 0 , flag = 0;
for(int i = 1 ; i <= n ; i++) {
while(temp <= m && person[temp].l <= song[i].l) {
se.insert(make_pair(person[temp].r , person[temp].pos));
temp++;
}
set<pair<int , int>>::iterator it;
it = se.lower_bound(make_pair(song[i].r , 0));
if(it == se.end()) {
flag = 1;
break;
}
else {
if(it->first >= song[i].r) {
ans[song[i].pos] = it->second;
gg[it->second].num--;
if(gg[it->second].num == 0) {
se.erase(it);
}
}
else {
flag = 1;
break;
}
}
}
if(flag) {
printf("NO\n");
}
else {
printf("YES\n");
for(int i = 1 ; i <= n ; i++) {
printf("%d " , ans[i]);
}
printf("\n");
}
return 0;
}
codeforces 496 E. Distributing Parts(贪心+set二分)的更多相关文章
- Codeforces Round #283 (Div. 2) E. Distributing Parts 贪心+set二分
E. Distributing Parts time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 【codeforces 496E】Distributing Parts
[题目链接]:http://codeforces.com/contest/496/problem/E [题意] 给你n个歌曲; 每个歌曲有一个需要声音的区间li,ri; 然后给你m个人; 每个人也有一 ...
- Distributing Parts
Distributing Parts 题目链接:http://codeforces.com/problemset/problem/496/E 贪心 将音乐和人都以低音升序排序,贪心处理低音更低的音乐, ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- [Codeforces 496E] Distributing Parts
[题目链接] https://codeforces.com/contest/496/problem/E [算法] 按右端点排序 , 每个乐曲优先选取的左端点最大的演奏家 用std :: set维护贪心 ...
- codeforces#1165 F2. Microtransactions (hard version) (二分+贪心)
题目链接: https://codeforces.com/contest/1165/problem/F2 题意: 需要买$n$种物品,每种物品$k_i$个,每个物品需要两个硬币 每天获得一个硬币 有$ ...
- 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)
F. Gourmet and Banquet time limit per test 2 seconds memory limit per test 512 megabytes input stand ...
随机推荐
- 【OpenCV-ANN神经网络自动驾驶】树莓派OpenCV神经网络自动驾驶小车【源码+实物】
没错!这个是我的毕业设计!!! 整个电子信息学院唯一一个优秀毕业设计 拿到这里炫耀了 实物如下: 电脑端显示效果: 自动驾驶实现过程: 1. 收集图像数据.建立局域网,让主机和Raspberry Pi ...
- 在表格中添加text便加框
private void createTableText(Table table) { TableEditor editor = new TableEditor(table); for (int i ...
- maysql的自增字段
因为mysql中的自增字段与oracle数据库是不一样的,所以在这里唠嗑一下mysql的自增字段 1.添加自增字段 1.1 在创建表时添加 create table emp( empno ) auto ...
- mysql新建用户及授权
添加用户 CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; -- username : 自定义用户名 -- localhost ...
- Hyper-v设置linux固定ip
一.创建CentOS 7专用的虚拟交换机 打开Hyper-v控制面板,找到右边的“虚拟交换机管理器” 进去后,点击“新建虚拟网络交换机”,填写名称后,选择“内部” 打开网络中心,修改配置如下图,注意i ...
- java多线程基础(二)--sleep(),wait,()yield()和join()方法
1.sleep()方法 在指定时间内让当前正在执行的线程暂停执行,但不会释放“锁标志”.不推荐使用. sleep()使当前线程进入阻塞状态,在指定时间内不会执行. 2.wait()方法 在其他线程调用 ...
- hadoop hdfs 分布式存储
1.克隆前的工作 1.配置好网络nat 需要设置静态ip并能通过主机上网 ssh 和 rsync 是必须下载的 2.yum install vim wget rsync ssh 并配 ...
- 编程杂谈——Non-breaking space
近日,意外地遇上件不寻常的事情.在解析PDF文件,读取其中内容的时候,对某一文件的处理,始终无法达到预期的效果. 解析方法如下: public void Parse(string value) { i ...
- (十四)c#Winform自定义控件-键盘(一)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- mysql row size上限
mysql innodb 的 row size上限 背景 在项目使用中,出现了以下报错: Error Code: 1118 - Row size too large (> 8126). Chan ...