题目链接: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. UE4 坐标系 坐标轴旋转轴

    Pitch是围绕Y轴旋转,也叫做俯仰角. Yaw是围绕Z轴旋转,也叫偏航角. Roll是围绕X轴旋转,也叫翻滚角. UE4里,蓝图中的rotation的三个依次为roll,pitch,yaw.C++中 ...

  2. FB的新专利竟要监看使用者的脸

    大家应该会很好奇Facebook又在搞什么新花招,这个专利的名称是"Techniques for emotion detection and content delivery",其 ...

  3. Extjs的使用总结笔记

    一:Extjs自带验证 1.alpha //只能输入字母,无法输入其他(如数字,特殊符号等) 2.alphanum//只能输入字母和数字,无法输入其他 3.email//email验证,要求的格式是& ...

  4. MQ如何解决消息的顺序性

    一.消息的顺序性 1.延迟队列:设置一个全局变量index,根据实际情况一次按照index++的逻辑一次给消息队列设置延迟时间段,可以是0.5s,甚至1s; 弊端:如果A,B,C..消息队列消费时间不 ...

  5. Hystrix超时测试

    package com.cookie.test; import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.Hystr ...

  6. 一文读懂tomcat组件--一个web服务器的架构演化史

    1. tomcat是谁?     2. tomcat可以做什么? tomcat是一个web容器,可以将web应用部署到tomcat,由它提供web服务,一个web容器中可以部署多个web应用,这些we ...

  7. alluxio源码解析-netty部分(2)

    netty简介 Netty是 一个异步事件驱动的网络应用程序框架,用于快速开发可维护的高性能协议服务器和客户端.   netty作为alluxio中重要的通讯组件 在常见的客户端上传,下载中,都会有n ...

  8. U盘重装MacOS-Sierra系统

    Mac系统重新安装两种方法: 1.在线远程重装. 2.制作启动U盘进行重装. 理论上第一种比较简单,但是会比较耗时,实际操作中,由于网上下载的系统版本低于我现在MacOS的版本,导致无法安装,因此只能 ...

  9. azure k8s netcore 程序初次部署

    以下都是我在2018年12月份做的实验,今天才发布出来. 念想 首先是了解一些关于K8s的一些基础概念,推荐查看一下这个链接,非常适合入门k8s.是因为K8S的环境搭建比较复杂(最主要是懒),其实也有 ...

  10. NLP(十五)让模型来告诉你文本中的时间

    背景介绍   在文章NLP入门(十一)从文本中提取时间 中,笔者演示了如何利用分词.词性标注的方法从文本中获取时间.当时的想法比较简单快捷,只是利用了词性标注这个功能而已,因此,在某些地方,时间的识别 ...