链接
http://poj.org/problem?id=3614
大意
给定所有牛的要求,给定一些东西,有一定数量,问最多能满足几头牛
思路
利用贪心,正确性我就不证明了
代码
#include<cstdio>
#include<algorithm>
#define r(i,a,b) for(register int i=a;i<=b;i++)
using namespace std;int n,m,ans;
struct node
{
int st,ed;
}cow[2501],rgy[2501];
bool operator<(node const &a,node const &b)
{
return a.st>b.st; //按照第一元素排序
}
signed main()
{
scanf("%d%d",&n,&m);
r(i,1,n) scanf("%d%d",&cow[i].st,&cow[i].ed);
r(i,1,m) scanf("%d%d",&rgy[i].st,&rgy[i].ed);
sort(cow+1,cow+1+n);
sort(rgy+1,rgy+1+m);
r(i,1,n)
r(j,1,m)
if(rgy[j].st>=cow[i].st&&rgy[j].st<=cow[i].ed&&rgy[j].ed)
{
ans++;
rgy[j].ed--;
break;
}
printf("%d",ans);
}