【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个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- .net基础总复习(3)
第三天 2.单例模式 1) 将构造函数私有化 2) 提供一个静态方法,返回一个对象 3) 创建一个单例 3.XML 可扩展的标记语言 XML:存储数据 注意: XML严格区分大小写,并且成对出现 ...
- JS中的异步
Hello,日常更新的我“浪”回来了!!! JS中有三座高山:异步和单线程.作用域和闭包.原型原型链 今天“浪”的主题是JS中的异步和单线程的问题. 主要从这三个方面入手 一.什么是异步(与同步作比较 ...
- sudo日志审计
一般企业生产环境都会用跳板机把操作日志记录下来,不过有些公司内部的测试机可以用本机的sudo日志审计功能将执行的sudo命令保存日志. 为什么要使用sudo审计,因为可以通过sudo授权给普通用户执行 ...
- Python3的URL编码解码
前言 博主最近在用python3练习一些爬虫脚本的时候,发现一些url的编码问题,在浏览器提交请求api时,如果url中包含汉子,就会被自动编码掉.呈现的结果是 ==> %xx%xx%xx.如果 ...
- Mybatis动态代理实现函数调用
如果我们要使用MyBatis进行数据库操作的话,大致要做两件事情: 1. 定义DAO接口 在DAO接口中定义需要进行的数据库操作. 2. 创建映射文件 当有了DAO接口后,还需要为该接口创建映射文件. ...
- CodeForces 362E Petya and Pipes
Petya and Pipes Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...
- Eclipse删除多余工作空间
选择perferences-->General -->Startup and Shutdown-->workspace-->选择多余的工作空间 -> remove -&g ...
- COGS——T 1168. 机器调度
http://www.cogs.pro/cogs/problem/problem.php?pid=1168 ★★ 输入文件:machine.in 输出文件:machine.out 简单对比 ...
- Ubuntu安装keepalived
Ubuntu安装keepalived 一.Keepalived是什么鬼东西: keepalived是集群管理中保证集群高可用的一个服务软件,其功能类似于heartbeat,用来防止单点故障. 二.Ke ...
- [HTML5] Inlining images with SVG and data URIs
The main reason you want to do I"nlining images with SVG and data URIs" is to reduce http ...