hdu 6003 Problem Buyer(贪心)

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.  AicBi . 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


1T100.
1N,M105.
1AiBi109.
1Ci109.
 

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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int N =1e5+10;
typedef long long LL;
const LL mod = 1000000007;
typedef pairpi;
struct node
{
    int l, r;
    bool operator <(const node &A)const
    {
        if(l!=A.l) return lA.r;
    }
}p[N];
int c[N];
priority_queue,greater >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=c[i])
                {
                    q.push(p[pos].r);
                }
                pos++;
            }
            while(!q.empty()&&q.top()





你可能感兴趣的:(思维,Greedy)