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", &A[I].S, &A[I].E);
} for (int i = 1; I <= m; i++) {scanf ("%d%d", &B[I].S, &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); }