hdu 6003 Problem Buyer(贪心)
来源:互联网 发布:淘宝女士打底衫 编辑:程序博客网 时间:2024/06/05 03:17
Problem Buyer
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 195 Accepted Submission(s): 60
Problem Description
TopSetter is an organization that creates problems. They’ve prepared N problems with estimated difficulty score in range [ Ai,Bi ]. TopHoster would like to host a contest consisting of M problems.
Theith problem should be of difficulty score Ci . The ith problem from TopSetter can be used in the contest if and only if its estimated difficulty score range [Ai,Bi] covers the difficulty score c of its target problem in the contest, i.e. Ai≤c≤Bi . Hosting a contest with M problems needs tohave M distinct problems which satisfy the required difficulty scores for each problem.
Unfortunately, TopSetter doesn’t provide a service to buy specific problems. You can only request a problem set containing K problems and they will give you K distinct problems from all the N problems, but you don’t know which problems will be given.
As TopSetter is the only problem provider for TopHoster, TopHoster would like to know the least number K of problems they need to buy to make sure they can host a contest.
The
Unfortunately, TopSetter doesn’t provide a service to buy specific problems. You can only request a problem set containing K problems and they will give you K distinct problems from all the N problems, but you don’t know which problems will be given.
As TopSetter is the only problem provider for TopHoster, TopHoster would like to know the least number K of problems they need to buy to make sure they can host a contest.
Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with 2 integers, N and M. Then N lines follow, each line consists of 2 integers representing the difficulty score range of the ith problem, AiandBi . The last line of each test case consists of M integers representing the target difficulty scores of the M problems Ci .
Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the least number of problems which the TopHoster needs to buy.
Output “IMPOSSIBLE!” if it’s impossible.
∙1≤T≤100.
∙1≤N,M≤105.
∙1≤Ai≤Bi≤109.
∙1≤Ci≤109.
Output “IMPOSSIBLE!” if it’s impossible.
limits
Sample Input
33 11 42 35 633 21 103 47 94 83 31 25 68 91 5 10
Sample Output
Case #1: 2Case #2: 2Case #3: IMPOSSIBLE!
读了好久连题目意思都读不懂。。。
真是一道超级难想的贪心题
题意:给出n个区间,m个数,让你任意选k个数,使一定能包含这m个数,一个区间只能包含一个数 求最小的k
解:难就难在 任意 二字 解题思路是 求出一个数的所有满足区间 那么这个区间取一个数即可包含这个数 那么ans=n-size+1
解题报告:http://www.cnblogs.com/xiaochaoqun/p/7243606.html
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <bitset>#include <algorithm>#include <climits>#include <bits/stdc++.h>using namespace std;const int N =1e5+10;typedef long long LL;const LL mod = 1000000007;typedef pair<int,int>pi;struct node{ int l, r; bool operator <(const node &A)const { if(l!=A.l) return l<A.l; else return r>A.r; }}p[N];int c[N];priority_queue<int,vector<int>,greater<int> >q;int main(){ int t, ncase=1; scanf("%d", &t); while(t--) { int n, m; scanf("%d %d", &n, &m); for(int i=0;i<n;i++) scanf("%d %d", &p[i].l,&p[i].r); for(int i=0;i<m;i++) scanf("%d", &c[i]); sort(p,p+n); sort(c,c+m); int ans=-1; while(!q.empty()) q.pop(); int pos=0; for(int i=0;i<m;i++) { while(pos<n&&p[pos].l<=c[i]) { if(p[pos].r>=c[i]) { q.push(p[pos].r); } pos++; } while(!q.empty()&&q.top()<c[i]) q.pop(); if(q.empty()) { ans=-1; break; } ans=max(ans,n-(int)q.size()+1); q.pop(); } if(ans==-1) printf("Case #%d: IMPOSSIBLE!\n",ncase++); else printf("Case #%d: %d\n",ncase++,ans); } return 0;}
阅读全文
0 0
- hdu 6003 Problem Buyer(贪心)
- HDU 6003 Problem Buyer(贪心)
- HDU 6003 Problem Buyer(鸽笼原理)
- HDU 5055 - Bob and math problem(贪心)
- hdu - 4974 - A simple water problem(贪心 + 反证)
- hdu - 4974 - A simple water problem(贪心 + 反证)
- HDU 5371 Hotaru's problem(Manacher算法+贪心)
- 规律,模拟,贪心(Travelling Salesman Problem,HDU 5402)
- HDU 4974 A simple water problem(贪心)
- HDU Problem - 1789 Doing Homework again【贪心】
- swustoj-Buyer(0195)(01背包)
- HDU Saving HDU (贪心)
- HDU Problem 1052 Tian Ji -- The Horse Racing 【贪心】
- HDU Problem—2124 Repair the Wall 【贪心】
- HDU 5920 Ugly Problem CCPC长春赛区 贪心
- hdu 5920 Ugly Problem 贪心构造 大整数
- hdu 2570 (贪心)
- hdu 4647(贪心?!)
- 数据库查询优化的一些点——索引
- [斯特林数][DP]BZOJ 2159: Crash 的文明世界
- 23.笔记go语言——MongDB数据库使用
- JavaScript强制类型转换和隐式类型转换
- 初学者Android--WebView
- hdu 6003 Problem Buyer(贪心)
- oracle中的索引
- 如何在GitHub部署自己的个人网站
- Base64编码及其作用
- [LeetCode]11. Container With Most Water
- Ubuntu 上安装Mysql
- Mysql安装步骤(3)注意事项
- selenium在爬取中的使用
- 【bzoj3932】[CQOI2015]任务查询系统