Distributing Parts
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的更多相关文章
- 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 ...
- codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)
题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...
- [Codeforces 496E] Distributing Parts
[题目链接] https://codeforces.com/contest/496/problem/E [算法] 按右端点排序 , 每个乐曲优先选取的左端点最大的演奏家 用std :: set维护贪心 ...
- 【codeforces 496E】Distributing Parts
[题目链接]:http://codeforces.com/contest/496/problem/E [题意] 给你n个歌曲; 每个歌曲有一个需要声音的区间li,ri; 然后给你m个人; 每个人也有一 ...
- codeforces 496 E. Distributing Parts(贪心+set二分)
题目链接:http://codeforces.com/contest/496/problem/E 题意:有n场演出,每场演出都有限制的高音和低音.然后m个人给出每个人的极限高音和低音还有出场次数. 最 ...
- MEF Parts Sample
namespace Microshaoft.MEF.Contracts { using System; public delegate void ExceptionEventHandler<TS ...
- 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? ...
- 词性标注 parts of speech tagging
In corpus linguistics, part-of-speech tagging (POS tagging or POST), also called grammatical tagging ...
- AX 2012 Form and Parts
在AX 2012 中系统标准FORM 中绝大部分都应用parts,form 和parts 是不可分开. 说到底parts到底是什么呢? Parts :我个人理解是为了在一个form中的显示更多信息而存 ...
随机推荐
- ROC与AUC
一.ROC曲线 1.ROC曲线:接收者操作特征(receiveroperating characteristic),ROC曲线上每个点反映着对同一信号刺激的感受性. 横轴:负正类率(false pos ...
- [oc] instancetype vs id for Objective-C 【转】
原贴地址:http://blog.csdn.net/lyy_whg/article/details/12846055 http://www.iwangke.me/2013/01/06/instance ...
- 关于CachedRowSetImpl类
全称: com.sun.rowset.CachedRowSetImpl 父类: javax.sql.rowset.BaseRowSet 实现的接口: javax.sql.RowSet javax.sq ...
- idea导入web项目的部署
前几天 参考 http://zyjustin9.iteye.com/blog/2172712 这篇文章的部署,一直没有问题,今天又部署了一个项目,按照这个步骤,死活却不能部署成功.最后发现,原来是在部 ...
- libguestfs-tools 虚拟机磁盘管理工具
libguestfs-tools虚拟机磁盘管理工具: 官网:http://libguestfs.org/ 这是一个非常强大的虚拟机磁盘管理工具,该工具包内包含的工具有virt-cat.virt-df. ...
- ASP.NET Core: Getting Started with ASP.NET MVC Core
1. ASP.NET Core the Unified Framework ASP.NET Core的统一框架 2. New Solution Project 新的解决方案项目 src folder: ...
- mysql 异常处理
--该文章内容通过网络搜索组合, mysql 异常,可以自定义异常,再应用.也可使用系统默认的异常,捕获应用. 一.异常定义: DECLARE condition_name CONDITION FOR ...
- Angular-ui-router + oclazyload + requirejs实现资源随route懒加载
刚开始用angularjs做项目的时候,我用的是ng-router,觉得加载并不好.所以就用了ui-router,考虑到在app上网页加载速度太慢,所以我就想到了用懒加载,看下是否能提升性能,提高加载 ...
- magento中对获取的数据在前台进行分页显示
1.数据加载类class Bf170_Bf170Logistics_Block_Inquiry_Index extends Mage_Core_Block_Template { publ ...
- DataGrid 导出数据到 Excel
Private Sub GridToExl_Click() On Error Resume Next If DataGrid1.Columns.Count = 0 Then MsgBox " ...