【题目链接】
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 = ; i <= c; i++) scanf("%d%d",&a[i].MinSPF,&a[i].MaxSPF);
for (i = ; i <= l; i++) scanf("%d%d",&b[i].SPF,&b[i].cover);
sort(a+,a+c+,cmp1);
sort(b+,b+l+,cmp2);
for (i = ; i <= c; i++)
{
for (j = ; j <= l; j++)
{
if (b[j].cover >= && b[j].SPF >= a[i].MinSPF && b[j].SPF <= a[i].MaxSPF)
{
b[j].cover--;
ans++;
break;
}
}
}
printf("%d\n",ans); return ; }