【题目链接】:http://codeforces.com/contest/496/problem/E

【题意】



给你n个歌曲;

每个歌曲有一个需要声音的区间li,ri;

然后给你m个人;

每个人也有一个声音区间Li,Ri以及最多能唱的歌曲数目ki;

某个人能唱某首歌当且仅当Li<=li&&ri<=Ri

问你要如何分配这n首歌给哪些人唱

或输出无解;

【题解】



把和n+m个区间按照左端点排序;

左端点一样,就把人排在前面;

然后顺序枚举;

对于人,直接把它加入到multiset中;

(这里可以只存右端点,因为左端点没用了);

然后对于枚举到的歌;

看看multiset里面有没有人能够唱;

因为左端点肯定都比这首歌左;

所以只要看看右端点会不会比它大就好;

选哪个呢?

一定是选右端点最小的,但是在这首歌右边的人;

这样,能最大限度的利用其它人(右端点大的留在后面用,万一能唱右端点更大的歌的呢);

选定某个人之后,他能唱的歌数递减;

如果他已经不能唱歌了,就把它从multiset中取出来;

multiset的重载函数最好这样写,那个friend bool operator 老是出问题

    bool operator < (const node & temp)const{
return r<temp.r;
}

【Number Of WA】



1



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5+100; struct abc{
int l,r;
int flag,num,id;
}; struct abc1{
int l,r,num,id;
bool operator < (const abc1& tmp)const{
return r<tmp.r;
}
}; int n,m,ans[N],num[N];
abc a[N];
multiset <abc1> dic; void out(){
cout << "NO" <<endl;
exit(0);
} bool cmp(abc a,abc b){
if (a.l!=b.l)
return a.l < b.l;
else
return a.flag > b.flag;
} int main(){
//Open();
Close();
cin >> n;
rep1(i,1,n){
cin >> a[i].l >> a[i].r;
a[i].flag = 0,a[i].id = i;
}
cin >> m;
rep1(i,n+1,n+m){
cin >> a[i].l >> a[i].r >> num[i-n];
a[i].flag = 1,a[i].id = i-n;
}
sort(a+1,a+1+n+m,cmp);
rep1(i,1,n+m){
abc1 temp;
temp.l = a[i].l,temp.r = a[i].r,temp.id = a[i].id;
if (a[i].flag ==0){
if (dic.empty()) out();
multiset <abc1>::iterator t = dic.lower_bound(temp);
if (t == dic.end()) out();
ans[a[i].id] = t->id;
num[t->id]--;
if (!num[t->id]) dic.erase(t);
}else {
dic.insert(temp);
}
}
cout <<"YES"<<endl;
rep1(i,1,n) cout << ans[i] <<' ';
return 0;
}

【codeforces 496E】Distributing Parts的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 754A】Lesha and array splitting

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 750D】New Year and Fireworks

    time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...

  5. 【codeforces 750B】New Year and North Pole

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  7. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

随机推荐

  1. Python 绘图与可视化 seaborn

    Seaborn是一个基于matplotlib的Python数据可视化库.它提供了一个高级界面,用于绘制有吸引力且信息丰富的统计图形. 主页:http://seaborn.pydata.org/ 官方教 ...

  2. tomcat闪退无法启动 the catalina_home environment variable is not defined correctly this environment variable is needed to run this program

    未成功配置CATALINA_HOME 1.计算机>属性>环境变量, 新建环境变量.变量名为CATALINA_HOME ,变量值tomcat的解压目录,注意后面不用多加“\”或者“;” 2. ...

  3. SM32 USART与USB接收不定数据方法,标准库、HAL库都适用

    很多时候,我们使用串口或USB接收数据时,往往不知道PC端会发多长的数据下来, 为了解决这个不定数据接收问题,在此各提供一个解决思路. 串口数据不定接收: 由于STM32单片机带IDLE中断,所以利用 ...

  4. LaTeX 表格指定宽度并居中

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50532269 在绘制表格的时候,对于特 ...

  5. static方法调用

    Static方法调用,类名.方法名 int number = Integer.ParseInt(String ); 将字符串参数作为有符号的十进制整数进行解析 将数字解析成字节数组 Character ...

  6. oauth2.0里回调地址返回code中如何让code不显示在URL里?

    背景: 最近在调用对方提供的oauth2.0接口的时候,返回code在URL显示,但是会影响到本系统调用其他的菜单项的操作,所以想把返回的code值去掉. 解决办法:     想了各种解决办法,目前把 ...

  7. ubuntu下使用Nexus搭建Maven私服

    ubuntu下使用Nexus搭建Maven私服 1.私服简介: 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服, ...

  8. Xdoclet + Ant自己主动生成Hibernate配置文件

    在使用Hibernate的时候,过多的Hibernate配置文件是一个让人头疼的问题. 近期接触了Xdoclet这个工具. 它实际上就是一个自己主动代码生成的工具.Xdoclet不能单独执行,必须搭配 ...

  9. Linux下Makefile的automake生成全攻略

    作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的M ...

  10. IIS身份验证的配置

    前4者配置:localhost applicationHost.config <location path=""> 后2者配置:web.config 要点: 这6项尽管 ...