POJ 3614 Sunscreen Priority queue

Source: Internet
Author: User
There are n cows, each cow has an interval for it to endure the range of sunlight intensity, M sunscreen, each with SPF and Cover2 Properties, SPF represents the use of the sun can be used to change the intensity of Spf,cover representative use, the maximum number of cows can be satisfied. First, according to the SPF of the sunscreen according to the order from small to large, the interval of each cow according to the starting point from small to large sort, starting point as the end of the order from small to large, starting from the first sunscreen, find all the starting point is less than or equal to the SPF, and then put the end point into the priority queue, priority queue Put in the queue is definitely the starting point to meet, and is the installation starting point from small to large satisfied, so later put in the queue is also satisfied that the starting point is equal to the current enumeration of SPF, and then take out the end point in the queue with the minimum of the use of sunscreen, here is the greedy thought.
#include <cstdio> #include <cstring> #include <queue> #include <algorithm> #include <vector&
Gt
using namespace Std; struct Node {int s, E;}
A[3000], b[3000];
    BOOL CMP (Node A, Node B) {if (a.s! = B.S) return A.S < B.S;
return A.E < B.E;
    } int main () {priority_queue<int, vector<int>, greater<int> > Q;
    int n, m;

    scanf ("%d%d", &n, &m);
    for (int i = 1; I <= n; i++) {scanf ("%d%d", &AMP;A[I].S, &AMP;A[I].E);
    } for (int i = 1; I <= m; i++) {scanf ("%d%d", &AMP;B[I].S, &AMP;B[I].E);
    } sort (a+1, a+n+1, CMP);
    Sort (b+1, b+m+1, CMP);
    int k = 1, ans = 0;
        for (int i = 1; I <= m; i++) {int tmp = B[I].S;
            while (k <= n && a[k].s <= tmp) {Q.push (A[K].E);
        k++;
        } tmp = B[I].E;
        printf ("%d%d******\n", q.size (), TMP); while (tmp > 0 && q.sizE () > 0) {if (Q.top () >= b[i].s) {ans++;
            tmp--;
        } q.pop ();
}} printf ("%d\n", ans); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.