【codeforces 496E】Distributing Parts
【题目链接】: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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【55.70%】【codeforces 557A】Ilya and Diplomas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 754A】Lesha and array splitting
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- 【codeforces 750B】New Year and North Pole
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- redis 篇 - set
set 无序集合 sadd key value 127.0.0.1:6379[7]> sadd s 3 (integer) 1 127.0.0.1:6379[7]> smembers s ...
- elk集群配置配置文件中节点数配多少
配置elk集群时,遇到,elasticsearch配置文件中的一个配置discovery.zen.minimum_master_nodes: 2.这里是三配的2 看到某一位的解释是这样:为了避免脑裂, ...
- [JZOJ]100046【NOIP2017提高A组模拟7.14】收集卡片
Star 计划订购一本将要发行的周刊杂志,但他可不是为了读书,而是-- 集卡. 已知杂志将要发行 N 周(也就是 N 期),每期都会附赠一张卡片.Star 通 过种种途径,了解到 N 期杂志附赠的卡片 ...
- centos7最小化安装Oracle11gR2
1.准备CentOS 7 系统环境 我以 CentOS-7-x86_64-DVD-1511.iso 为例,简述Oracle 11g的安装过程. 由于是使用静默模式(silent)安装的,无需使用图形化 ...
- 硬核官宣:台积电官宣6nm及7nm加强版工艺!
台积电正式宣布了6nm(N6)工艺,在已有7nm(N7)工艺的基础上大幅度增强,号称可提供极具竞争力的高性价比,而且能加速产品研发.量产.上市速度. 这几年,曾经执行业牛耳的Intel在新工艺方面进展 ...
- vue 阿里云上传组件
vue 阿里云上传组件 Vue.js上传图片到阿里云OSS存储 测试项目git地址 本测试项目启动方法 示例链接 组件配置项 实践解释 本文主要介绍如何 在vue项目中使用web 直传方式上传阿里云o ...
- Python学习笔记(一):基本数据类型
在Python3种,有六种标准数据类型: 数字(Number) 字符串(String) 列表(List) 元组(Tuple) 集合(Set) 字典(Dictionary) 这六种数据类型中,数字类型和 ...
- 新手学python-Day4-作业
购物车程序 要求: 1.启动程序后,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检查余额是否足够,够了就扣款,不够就提醒 4.可随时退出,退出时,打印已购买 ...
- Python 爬虫练习: 爬取百度贴吧中的图片
背景:最近开始看一些Python爬虫相关的知识,就在网上找了一些简单已与练习的一些爬虫脚本 实现功能:1,读取用户想要爬取的贴吧 2,读取用户先要爬取某个贴吧的页数范围 3,爬取每个贴吧中用户输入的页 ...
- HDU 4372
想了很久,终于想到了.... 向后看到F,向前看到B,假如把N-1个楼分成F+B个组,则把每个组最高的楼作为看到的楼,那么,其实在确定每一组的最高楼时,左边或右边的最高楼的顺序已经确定了.由于是排列数 ...