题目链接: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. dubbo是如何控制并发数和限流的?

    ExecuteLimitFilter ExecuteLimitFilter ,在服务提供者,通过 的 "executes" 统一配置项开启: 表示每服务的每方法最大可并行执行请求数 ...

  2. 利用jQuery中的serialize方法大量获取页面中表单的数据,发送的服务器

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. React 如何搭建脚手架

    React 如何搭建脚手架   npm install -g create-react-app    //安装 create-react-app react-demo    // react-demo ...

  4. Python中input()的使用方法

    input()以字符串的方式获取用户输入: >>> x = input() 4.5 >>> type(x) <class 'str'> >> ...

  5. Scala类和对象(二)

    1. 类和属性 1.1 如何控制构造函数字段的可见性 在Scala中: 如果一个字段被声明为var, Scala会为该字段生成getter和setter方法. 如果字段是val, Scala只生成ge ...

  6. 给面试官讲明白:一致性Hash的原理和实践

    "一致性hash的设计初衷是解决分布式缓存问题,它不仅能起到hash作用,还可以在服务器宕机时,尽量少地迁移数据.因此被广泛用于状态服务的路由功能" 01分布式系统的路由算法 假设 ...

  7. 读取某个目录下的所有图片并显示到pictureBox

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. Map集合的遍历(利用entry接口的方式)

    核心思想: 调用map集合中的方法entrySet()将集合中的映射关系存放在Set集合中. 迭代Set集合 获取出的Set集合的元素是映射关系对象 通过映射关系对象方法的getKey(),getVa ...

  9. 【译】为什么要了解HTTP

    原文地址:Why should I care about HTTP? 原作信息:by Devon Campbell. Dec 15 '18 Originally published at raddev ...

  10. django 获取当前访问的URL

    next_url = request.path_info print(next_url) print(request.get_full_path()) //打印出全路径(路径和参数) print(re ...