Distributing Parts

题目链接:http://codeforces.com/problemset/problem/496/E

贪心

将音乐和人都以低音升序排序,贪心处理低音更低的音乐,找出低音小于等于它的歌手,二分查找高音与它最近的人。因为剩下的人的低音一定小于后面的歌的低音,而我们选择出了满足条件的高音的最小的人,让后面的歌尽有可能的有人唱。然而不知道为什么我用lower_bound(s.begin(),s.end(),modle)会TLE,而用s.lower_bound(modle)就能过,这两者实现不同吗?

代码如下:

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#define N 100005
using namespace std;
struct nod{
int l,r,num,index;
}musics[N],men[N];
int k[N],ans[N];
bool cmp(nod a,nod b){
if(a.l==b.l)return a.r<b.r;
return a.l<b.l;
}
int n,m;
int main(void){
scanf("%d",&n);
for(int i=;i<=n;++i){
musics[i].num=i;
scanf("%d%d",&musics[i].l,&musics[i].r);
}
sort(musics+,musics++n,cmp);
scanf("%d",&m);
for(int i=;i<=m;++i){
men[i].num=i;
scanf("%d%d%d",&men[i].l,&men[i].r,&k[i]);
}
sort(men+,men++m,cmp);
bool flag=;
int tt=;
set<pair<int,int> >s;
for(int i=;i<=n;++i){
while(tt<=m&&men[tt].l<=musics[i].l){
s.insert(make_pair(men[tt].r,men[tt].num));
tt++;
}
set<pair<int,int> >::iterator it;
it=s.lower_bound(make_pair(musics[i].r,));
if(it==s.end()){
flag=;
break;
}
if(musics[i].r<=it->first){
ans[musics[i].num]=it->second;
k[it->second]--;
if(k[it->second]==)
s.erase(*it);
}else{
flag=;
break;
}
}
if(flag){
printf("YES\n");
for(int i=;i<=n;++i)
printf("%d%c",ans[i],n==i?'\n':' ');
}else printf("NO\n");
}

Distributing Parts的更多相关文章

  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 497c//Distributing Parts// Codeforces Round #283(Div. 1)

    题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...

  3. [Codeforces 496E] Distributing Parts

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

  4. 【codeforces 496E】Distributing Parts

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

  5. codeforces 496 E. Distributing Parts(贪心+set二分)

    题目链接:http://codeforces.com/contest/496/problem/E 题意:有n场演出,每场演出都有限制的高音和低音.然后m个人给出每个人的极限高音和低音还有出场次数. 最 ...

  6. MEF Parts Sample

    namespace Microshaoft.MEF.Contracts { using System; public delegate void ExceptionEventHandler<TS ...

  7. How can I protect derived classes from breaking when I change the internal parts of the base class?

    How can I protect derived classes from breaking when I change the internal parts of the base class? ...

  8. 词性标注 parts of speech tagging

    In corpus linguistics, part-of-speech tagging (POS tagging or POST), also called grammatical tagging ...

  9. AX 2012 Form and Parts

    在AX 2012 中系统标准FORM 中绝大部分都应用parts,form 和parts 是不可分开. 说到底parts到底是什么呢? Parts :我个人理解是为了在一个form中的显示更多信息而存 ...

随机推荐

  1. HttpContext.Current.Request.ServerVariables

    Request.ServerVariables("Url") 返回服务器地址Value 0: /WebSite1/Default.aspx Request.ServerVariab ...

  2. CodeForces 213B Numbers

    $dp$,组合数. $dp[i][j]$表示只用数字$i$,$i+1$,$i+2$......,$9$,凑成长度为$j$的并且数字$i$到$9$符合要求的方案数.只要枚举数字$i$用几个就可以转移了. ...

  3. CART分类与回归树与GBDT(Gradient Boost Decision Tree)

    一.CART分类与回归树 资料转载: http://dataunion.org/5771.html        Classification And Regression Tree(CART)是决策 ...

  4. SqlDataReader中的GetSqlValue()方法

    sdr.GetValue(0) "Title"sdr.GetValue(1)4sdr.GetValue(2)falsesdr.GetValue(3)0sdr.GetValue(4) ...

  5. 解决IE浏览器“无法显示此网页”的问题

    诊断后提示:远程计算机或设备不接受连接 其他浏览器可以正常使用,QQ什么的也都正常,只有IE不能上网诊断提示:远程计算机或设备将不接受连接 ,网上找了好多方法都行不通.最后发现了这种方法,问题简单解决 ...

  6. 常见的 http 状态码

    1~5开头的HTTP状态码分别表示: 1XX 表示消息 2XX 表示成功 3XX 表示重定向 4XX 表示请求错误 5XX 表示服务端错误 常见的HTTP状态码: 200 OK 表示请求成功 一切正常 ...

  7. error: a label can only be part of a statement and a declaration is not a statement

    GCC: error: a label can only be part of a statement and a declaration is not a statement switch(a){ ...

  8. 算法系列——huffman编码

    哈夫曼编码,旨在对信息实现一种高效的编码,这种编码中任何一个都不是其他编码的前缀码.因此,在实际接收时,一旦匹配,就可以立即解码. 具体算法过程可以参加网上的很多教程. 给出一个自己的实现,一方面加强 ...

  9. 第 2 章 Node.js 中的交互式运行环境 —— REPL

    本章内容包括: 如何使用REPL运行环境以及如何在该运行环境中测试各种JavaScript表达式. 如何定义并启动REPL运行环境. Node.js 框架中为REPL运行环境提供了哪些命令以及这些命令 ...

  10. C++类的实例化的两种方法

    C++ 类的实例化有两种方法: 直接定义对象: 先定义一个类:   class A { public: A(); virtual ~A(); ... ... };   类实现略. 用的时候: A a; ...