HDU 6003 Problem Buyer(贪心)
来源:互联网 发布:2016淘宝助理手机版 编辑:程序博客网 时间:2024/06/07 00:47
/**E - Problem Buyer 题意:主持人主持一场比赛需要M个题目,每个题目的难度要求是Ci,一个公司提供M个题目,每个题目的难度为[Ai,Bi],问主持人最少需要购买多少个题目才能保证一定能办成这个比赛(买K个题目的时候公司从M个题目中任意挑选K个),不满足输出impossible思路:对区间按左端点为关键字从小到大排序,举办比赛题目的难度从小到大排序,枚举每个难度,最终的结果一定是这样的:买的K个题目的前K-1个题目的区间一定不包含这个难度,而最后一个满足,难度从左到右扫描,优先队列维护在这个点的区间数量,然后取max(n - 队列size+1)+1是因为最后一个区间一定包含这个难度,最后扫描完一个点在队列要pop一个,代表需要给这个点一个区间,因为可能Ci, Ci+1都在一个区间内**/#include<cstdio>#include<cstring>#include<queue>#include<algorithm>typedef long long ll;const int maxn = 1e5 + 10;const int INF = 1e8;using namespace std;typedef pair<int, int> par;int T, n, m, kase = 1;int C[maxn];par pa[maxn];int main() { scanf("%d", &T); while(T--) { scanf("%d %d", &n, &m); for(int i = 0; i < n; i++) scanf("%d %d", &pa[i].first, &pa[i].second); for(int i = 0; i < m; i++) scanf("%d", &C[i]); priority_queue<int, vector<int>, greater<int> > que; sort(pa, pa + n); sort(C, C + m); int ans = 0; for(int i = 0, it = 0; i < m; i++) { while(it < n && pa[it].first <= C[i]) que.push(pa[it++].second); while(!que.empty() && que.top() < C[i]) que.pop(); if(que.empty()) { ans = -1; break; } ans = max(ans, n - (int)que.size()); que.pop(); } if(ans != -1) printf("Case #%d: %d\n", kase++, ans + 1); else printf("Case #%d: IMPOSSIBLE!\n", kase++); } return 0;}
阅读全文
0 0
- HDU 6003 Problem Buyer(贪心)
- hdu 6003 Problem Buyer(贪心)
- HDU 6003 Problem Buyer(鸽笼原理)
- HDU 4974 A simple water problem(贪心)
- HDU Problem - 1789 Doing Homework again【贪心】
- HDU 5055 - Bob and math problem(贪心)
- hdu - 4974 - A simple water problem(贪心 + 反证)
- hdu - 4974 - A simple water problem(贪心 + 反证)
- HDU 5371 Hotaru's problem(Manacher算法+贪心)
- HDU Problem 1052 Tian Ji -- The Horse Racing 【贪心】
- HDU Problem—2124 Repair the Wall 【贪心】
- HDU 5920 Ugly Problem CCPC长春赛区 贪心
- hdu 5920 Ugly Problem 贪心构造 大整数
- 规律,模拟,贪心(Travelling Salesman Problem,HDU 5402)
- Codeforces442B_Andrey and Problem(贪心)
- An Easy Problem --- 贪心
- 贪心算法 problem M
- HDU 贪心
- Matlab中维度的理解
- Switch与ToggleButton
- jemalloc横向分析(三) arena_run_split_large使用分配的chunk存放tcache
- nexus发布项目与创建工厂
- ssm整合意外报空指针
- HDU 6003 Problem Buyer(贪心)
- 51 nod1286三段子串
- spring中reques的运用
- tensorflow的tf.reduce_mean()函数的使用方法
- mybatis入门基础(五)----动态SQL
- 快速排序
- 笨方法学Python 习题 9: 打印,打印,打印
- 上班遇到的坑
- Tree----- 99. Recover Binary Search Tree