【题目链接】
http://poj.org/problem?id=3614
【算法】
将MinSPF从大到小排序,每头牛找SPF值最大的防晒霜
【代码】
#include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <exception> #include <fstream> #include <functional> #include <limits> #include <list> #include <map> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <vector> #include <cwchar> #include <cwctype> #include <stack> #include <limits.h> using namespace std; #define MAXC 2510 int i,j,c,l,ans; struct Infoa { int MinSPF,MaxSPF; } a[MAXC]; struct Infob { int SPF,cover; } b[MAXC]; inline bool cmp1(Infoa a,Infoa b) { return a.MinSPF > b.MinSPF; } inline bool cmp2(Infob a,Infob b) { return a.SPF > b.SPF; } int main() { scanf("%d%d",&c,&l); for (i = 1; i <= c; i++) scanf("%d%d",&a[i].MinSPF,&a[i].MaxSPF); for (i = 1; i <= l; i++) scanf("%d%d",&b[i].SPF,&b[i].cover); sort(a+1,a+c+1,cmp1); sort(b+1,b+l+1,cmp2); for (i = 1; i <= c; i++) { for (j = 1; j <= l; j++) { if (b[j].cover >= 1 && b[j].SPF >= a[i].MinSPF && b[j].SPF <= a[i].MaxSPF) { b[j].cover--; ans++; break; } } } printf("%d ",ans); return 0; }