题目链接: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. host配置

    host添加地址 今天是我第一天入职,坐到工位的第一件事就是配置host,因为连接测试环境需要本地授权,所以要配置.这里简单记录下配置中遇到的问题和操作的步骤 操作环境是win10,之前公司一直使用的 ...

  2. JDK的命令行工具系列 (三) jhat、jstack

    jhat: heapdump文件分析工具 在前两篇系列文章JDK的命令行工具系列 (一) jps.jstat.JDK的命令行工具系列 (二) javap.jinfo.jmap中, 我们已经介绍过了jp ...

  3. Java性能权威指南读书笔记--之二

    新生代填满时,垃圾收集器会暂停所有的应用线程,回收新生代空间.这种操作被称为Minor GC. 老年代被填满时,垃圾收集器会暂停所有应用线程,对其进行回收,接着对堆空间进行整理.这个过程被称为Full ...

  4. 中间件增强框架之-CaptureFramework框架

    一.背景 应用服务监控是智能运维系统的重要组成部分.在UAV系统中,中间件增强框架(MOF)探针提供了应用画像及性能数据收集等功能,其中数据收集功能主要采集四类数据:实时数据.画像数据.调用链接数据生 ...

  5. mysql主从配置详解(图文)

    最近工作不是很忙,把以前整理的mysql数据库的主从配置过程记录一下,有不足之处,请各位多多纠正指教 #环境配置#master IP:192.168.46.137 slave IP:192.168.4 ...

  6. Spring注解浅入浅出——不吹牛逼不装逼

    Spring注解浅入浅出——不吹牛逼不装逼 前情提要 上文书咱们说了<Spring浅入浅出>,对Spring的核心思想看过上篇的朋友应该已经掌握了,此篇用上篇铺垫,引入注解,继续深入学习. ...

  7. Apache ActiveMQ任意文件写入漏洞(CVE-2016-3088)复现

    Apache ActiveMQ任意文件写入漏洞(CVE-2016-3088)复现 一.漏洞描述 该漏洞出现在fileserver应用中,漏洞原理:ActiveMQ中的fileserver服务允许用户通 ...

  8. Spring Cloud微服务接口这么多怎么调试

    导读 我们知道在微服务架构下,软件系统会被拆分成很多个独立运行的服务,而这些服务间需要交互通信,就需要定义各种各样的服务接口.具体来说,在基于Spring Cloud的微服务模式中,各个微服务会基于S ...

  9. mysql优化---订单查询优化(1):视图优化+索引创建

    订单的表结构采用了垂直分表的策略,将订单相关的不同模块的字段维护在不同表中 在订单处理这个页面,需要查询各种维度, 因此为了方便查询创建了v_sale_order视图(老版本) drop view v ...

  10. Mybatis学习笔记之---动态sql中标签的使用

    动态Sql语句中标签的使用 (一)常用标签 1.<if> if标签通常用于WHERE语句中,通过判断参数值来决定是否使用某个查询条件, 他也经常用于UPDATE语句中判断是否更新某一个字段 ...