hdu 6003 Problem Buyer(贪心)
2017-09-29 20:15
344 查看
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.
The ith 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.
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.
limits
∙1≤T≤100.∙1≤N,M≤105.
∙1≤Ai≤Bi≤109.
∙1≤Ci≤109.
Sample Input
3
3 1
1 4
2 3
5 6
3
3 2
1 10
3 4
7 9
4 8
3 3
1 2
5 6
8 9
1 5 10
Sample Output
Case #1: 2
Case #2: 2
Case #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
;
int c
;
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;
}
相关文章推荐
- HDU 6003 Problem Buyer(贪心)
- HDU 5055 - Bob and math problem(贪心)
- hdu6003 Problem Buyer 贪心 给定n个区间,以及m个数,求从n个区间中任意选k个区间,满足m个数都能在k个区间中找到一个包含它的区间,如果一个区间包含了x,那么 该区间不能再去包含另一个数,即k>=m。求最小的k。如果不存在这样的k,输出“IMPOSSIBLE!”。
- hdu - 4974 - A simple water problem(贪心 + 反证)
- HDU 4976 A simple greedy problem. 贪心+DP
- http://acm.hdu.edu.cn/showproblem.php?pid=1789 很好的贪心题目
- hdu - 4974 - A simple water problem(贪心 + 反证)
- HDU 4974 A simple water problem(贪心)
- HDU 5920 Ugly Problem CCPC长春赛区 贪心
- HDU 5055 Bob and math problem(贪心)——BestCoder Round #11(div.2)
- HDU 4974 A simple water problem(贪心)
- hdu----(5055)Bob and math problem(贪心)
- Ugly Problem HDU - 5920 模拟+贪心。。
- hdu 5055 Bob and math problem (很简单贪心)
- 规律,模拟,贪心(Travelling Salesman Problem,HDU 5402)
- hdu - 4974 - A simple water problem(贪心 + 反证)
- 【HDU 1051】Wooden Sticks(贪心)
- HDU 1023 Train Problem II 卡特兰数 大数的乘法除法
- hdu 2058 The sum problem
- HDU 3420 Bus Fair(贪心)