【题目链接】: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;elsereturn 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;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626260.html

【codeforces 496E】Distributing Parts相关推荐

  1. 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

    题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...

  2. 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

    题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...

  3. 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

    题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...

  4. 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)

    题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...

  5. 【CodeForces 997C】Sky Full of Stars(组合计数)

    题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...

  6. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  7. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  8. 【codeforces 711B】Chris and Magic Square

    [题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...

  9. 【codeforces 807C】Success Rate

    [题目链接]:http://codeforces.com/contest/807/problem/C [题意] 给你4个数字 x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b) ...

  10. 【codeforces 766E】Mahmoud and a xor trip

    [题目链接]:http://codeforces.com/contest/766/problem/E [题意] 定义树上任意两点之间的距离为这条简单路径上经过的点; 那些点上的权值的所有异或; 求任意 ...

最新文章

  1. 激光雷达Lidar与毫米波雷达Radar:自动驾驶的利弊
  2. SD-WAN — 技术架构
  3. mono beta 3 released
  4. 从微信红包的春节活动运营方案中,必读的运营策略
  5. get_attribute中的value是什么类型的?_建设工程项目中都有什么类型的监理?
  6. js 闭包作用域和作用域链_Java:伪造工厂的闭包以创建域对象
  7. [EffectiveC++]item02:尽量以const,enum,inline代替#define
  8. if-else嵌套太深?教你一个新手都能掌握的设计模式搞定!
  9. 在请求目标中找到无效字符。有效字符在RFC 7230和RFC 3986中定义
  10. 标识符——Python
  11. 判断数组中的元素是否连续
  12. 破解密码——利用粘滞键漏洞破解Windows 7 PIN
  13. python文件(.py)转换为可执行文件(.exe)操作
  14. 微信关注公众号获取用户信息
  15. android usb otg 查看,android USB OTG功能如何打开及实现
  16. java调用支付宝扫码支付接口
  17. QQTIM怎么成功修改个人文件夹保存位置
  18. The Softer Side of the Architect
  19. 外卖O2O硝烟初起巨头们各自是啥思路?
  20. 读书印记 - 《反脆弱》

热门文章

  1. python读取excel写入mysql_使用Python读Excel数据Insert到MySQL
  2. jquery 设置背景
  3. 8.3分叉/结合的框架(Fork/Join Framework)
  4. 【渝粤教育】国家开放大学2018年秋季 0299-22T中国古代文学(1) 参考试题
  5. 【渝粤教育】国家开放大学2019年春季 690化工原理及实验 参考试题
  6. LeetCode刷题系列(二)二分查找、二叉排序树 的应用
  7. 人工智能的下个十年在推理?
  8. 将自己电脑的SSH key添加到GitHub上
  9. 在linux 或docker中使用 system.drawing.common
  10. html2canvas 在手机app端的问题