五月个人赛-a problem of DP(贪心,multiset)
来源:互联网 发布:python命令行运行文件 编辑:程序博客网 时间:2024/06/06 03:48
Problem Description
The final exam is coming, and finding classrooms for exams is always a headache for teachers , so teachers find you to assign the classrooms for exam.
There are n exams that need to be assigned and k classrooms that you can choose. Every proposed exam has starting time si and ending time ei. Any such an exam should take place at one of the classrooms. Any of the k classrooms is big enough to hold any number of the students that take the exam, and each classroom can hold at most one exam at any time, which means no two proposed exams can take place at the same classroom at the same time. Even if two proposed exams overlap momentarily (the ending time of one activity equals the starting time another activity), they can not be assigned to the same classroom.
There are so many proposed exam that there may not be enough classrooms to assign all the exams. It is desirable to have as many exams as possible. At most how many proposed exams can be assigned to the classrooms?
There are T groups of test data. The first line contains one positive integer T(1<=T<=100).
For each test data : the first line contains two positive integers n and k (1<=k<=n<=200000 ), representing the number of proposed exams and number of classrooms, respectively.
The following n lines each contains two positive integers: the i th line among these n lines contains si and ei (1<=si<=ei<=10^9), indicating the starting time and ending time of proposed exam i
Output an integer indicating the maximum number proposed exams that can be scheduled.
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <queue>#include <set>using namespace std;const int num = 200100;struct exam{ int s, e; bool operator < (const exam& a) const { return e < a.e; }};exam ex[num];multiset<long long> q;int main(){ //freopen("1.txt", "r", stdin); int t; cin >> t; while( t --) { q.clear(); int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >>ex[i].s >> ex[i].e; for(int i = 1; i <= k; i ++) q.insert(0); sort(ex + 1, ex + n + 1); int cnt = 0; for(int i = 1; i <= n; i ++) { multiset<long long>::iterator it = q.lower_bound(ex[i].s); if(it != q.begin()) { it --; q.erase(it); q.insert(ex[i].e); cnt ++; } } // for(multiset<long long>::iterator it = q.begin(); it != q.end(); it ++) cout << *it << endl; cout << cnt << endl; } return 0;}
- 五月个人赛-a problem of DP(贪心,multiset)
- [HAOI2011]problem a(DP)
- 2016寒假个人赛(1)A(贪心)
- TJU-4107. A simple problem(贪心)
- [BZOJ2298][HAOI2011]problem a(DP)
- pku2295 A DP Problem
- Zju2492 A Dp Problem
- A problem of sorting
- 【贪心】【TOJ4107】【A simple problem】
- 贪心算法—Problem A
- 贪心算法 Problem A 1000
- USC Problem A 钓鱼 贪心
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend(贪心+DP)
- 五月个人赛-Easy to improve(大数据,找规律)
- hdu - 4974 - A simple water problem(贪心 + 反证)
- hdu - 4974 - A simple water problem(贪心 + 反证)
- Uva---11520Problem A Fill the Square (贪心+模拟)
- ACDream 1734 Can you make a water problem?(贪心)
- paulzhou的数学?TAT? 数学思维
- Xcode9.0打包IOS APP问题总结
- JavaScript 特效三大系列总结
- iptables详解
- SSH总结
- 五月个人赛-a problem of DP(贪心,multiset)
- Oracle那些事(3)-企业管理器DataBase Control使用说明
- 400. Nth Digit
- 软考新思维--2017年上半年信息系统项目管理师上午试题分析与答案(试题36-40题)
- 网银支付处理 | 京东支付处理
- 简述vin码识别车架号识别
- UI基础控件综合案例之Java代码编写
- spring之入门程序
- Linux问题