题目链接: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二分)的更多相关文章

  1. 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 ...

  2. 【codeforces 496E】Distributing Parts

    [题目链接]:http://codeforces.com/contest/496/problem/E [题意] 给你n个歌曲; 每个歌曲有一个需要声音的区间li,ri; 然后给你m个人; 每个人也有一 ...

  3. Distributing Parts

    Distributing Parts 题目链接:http://codeforces.com/problemset/problem/496/E 贪心 将音乐和人都以低音升序排序,贪心处理低音更低的音乐, ...

  4. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  5. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  6. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  7. [Codeforces 496E] Distributing Parts

    [题目链接] https://codeforces.com/contest/496/problem/E [算法] 按右端点排序 , 每个乐曲优先选取的左端点最大的演奏家 用std :: set维护贪心 ...

  8. codeforces#1165 F2. Microtransactions (hard version) (二分+贪心)

    题目链接: https://codeforces.com/contest/1165/problem/F2 题意: 需要买$n$种物品,每种物品$k_i$个,每个物品需要两个硬币 每天获得一个硬币 有$ ...

  9. 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)

    F. Gourmet and Banquet time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

随机推荐

  1. 自己动手,开发轻量级,高性能http服务器。

    前言 http协议是互联网上使用最广泛的通讯协议了.web通讯也是基于http协议:对应c#开发者来说,asp.net core是最新的开发web应用平台.由于最近要开发一套人脸识别系统,对通讯效率的 ...

  2. Redis优化建议

    优化的一些建议 1.尽量使用短的key 当然在精简的同时,不要完了key的"见名知意".对于value有些也可精简,比如性别使用0.1. 2.避免使用keys * keys *, ...

  3. 有容云-PPT | 当微服务遇见容器

    编者注: 本文为10月29日有容云高级技术顾问龙淼在Docker Live时代线下系列-广州站中演讲的PPT,本次线下沙龙为有容云倾力打造Docker Live时代系列主题线下沙龙,每月一期畅聊容器技 ...

  4. abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十二)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...

  5. 并发知识(2)——关于Thread

    一些容易混淆的知识点 sleep vs wait sleep是Thread,wait是Object方法 wait和notify只能在同步代码块中调用 wait释放锁资源,sleep不释放锁资源 唤醒条 ...

  6. 邻域保持嵌入(NPE)

    传统的线性降维方法,如主成分分析(PCA).因子分析(FA)等,关注的是样本的方差,能学习线性流形的结构,却无法学习非线性流形.而经典的流形学习方法虽然能够学习非线性流形结构,但由于本身属于直推学习, ...

  7. koa2图片上传成功后返回服务器地址,实时显示服务器图片

    版本:node(8.5.0); koa(2.4.1); koa-router(7.3.0); koa-body(2.5.0); koa-static(4.0.2); 代码实现 const fs = r ...

  8. 【PYTHON】语法基础 | 开始使用Python

    Python的热度不言而喻,机器学习.数据分析的首选语言都是Python,想要学习Python的小伙伴也很多,我之前也没有认真用过Python,所以也想体验一下它的魅力,索性花了两天集中看了一下它的基 ...

  9. javaScript基础-04 对象

    一.对象的基本概念 对象是JS的基本数据类型,对象是一种复合值,它将很多值(原始值或者对象)聚合在一起,可通过名字访问这些值,对象也可看做是属性的无序集合,每个属性都是一个名/值对.对象不仅仅是字符串 ...

  10. Java学习|String,StringBuffer,StringBuilder?

    1 String   (1) String的创建机理 由于String在Java世界中使用过于频繁,Java为了避免在一个系统中产生大量的String对象,引入了字符串常量池.其运行机制是:创建一个字 ...