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. Kafka connect快速构建数据ETL通道

    摘要: 作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 业余时间调研了一下Kafka connect的配置和使用,记录一些自己的理解和心得,欢迎 ...

  2. 逃出克隆岛 (codevs 2059)

    较普通的走迷宫的题 传送门 :codevs 2059 逃出克隆岛 思路 :BFS 即可    PS :传送门 不必重复使用 #include <iostream> #include < ...

  3. solr最佳实践

    管理页面 页面地址:http://{ip}:{port}/solr/#/ 管理页面的data-import页可以手动重建索引,configuration指定了数据源,重建索引也可以通过http请求触发 ...

  4. BIEE基本函数

    一,TRIM ,去除空字符 TRIM(EXPR) SUBSTRING("UT TIME"."月份" FROM 6 FOR 2) 1.AGGREGATE AT 此 ...

  5. ele.me在IOS浏览器端启动APP的技巧分析

    ele.me在IOS浏览器端启动APP的技巧分析 巧妙利用后台重定向,在schemes启动时提示用户打开,启动不了APP时能够及时跳转至下载页面. 避免报错页面的出现以及用户还没来的及选择就跳转到下载 ...

  6. AndroidPullToRefresh拉动效果配置

    最近用了 开源的 AndroidPullToRefresh 库,但是发现拉动时的效果有个很奇怪的地方,无论上下拉动,当列表滚动到顶部或底部时,会瞬间弹出半个列表高度的拉动提示,感觉很不舒服,这种提示根 ...

  7. JavaScript进阶(一)

     OK接下来,我们再次梳理一遍js并且提高一个等级. 众所周知,web前端开发者需要了解html和css,会只用html和css创建一个漂亮的页 面,但是这肯定是不够的,因为它只是一个静态的页面,我们 ...

  8. c语言对齐问题

    引言 考虑下面的结构体定义: typedef struct{ char c1; short s; char c2; int i; }T_FOO; 假设这个结构体的成员在内存中是紧凑排列的,且c1的起始 ...

  9. Linux Tomcat 自启动

    使用chkconfig命令 修改tomcat/bin/startup.sh,在开头的地方添加如下内容 #chkconfig: #description:tomcat auto start #proce ...

  10. [SOJ]连通性问题

    Description 关系R具有对称性和传递性.数对p q表示pRq,p和q是0或自然数,p不等于q.要求写一个程序将数对序列进行过滤,如果一个数对可以通过前面数对的传递性得到,则将其滤去.例如:输 ...