poj 3614 Sunscreen
Description–
有C个奶牛去晒太阳 (1 <=C <= 2500),每只奶牛各自能够忍受的阳光强度有一个minSPF[i]和一个maxSPF[i]值,太大就晒伤了,太小奶牛没感觉。
而刚开始的阳光的强度非常大,奶牛都承受不住,然后奶牛就得涂抹防晒霜,防晒霜的作用是让阳光照在身上的阳光强度固定为某个值。
那么为了不让奶牛烫伤,又不会没有效果,给出了L种防晒霜 (1 <=L <= 2500)。每种的数量cover[i]和固定的阳光强度SPF[i]也给出来了
每个奶牛只能抹一瓶防晒霜,最后问能够享受阳光浴的奶牛有几只。
Input–
-
Line 1: Two space-separated integers: C and L
-
Lines 2…C+1: Line i describes cow i’s lotion requires with two integers: minSPFi and maxSPFi
-
Lines C+2…C+L+1: Line i+C+1 describes a sunscreen lotion bottle i with space-separated integers: SPFi and coveri
Output–
A single line with an integer that is the maximum number of cows that can be protected while tanning
Sample Input–
3 2
3 10
2 5
1 5
6 2
4 1
Sample Output–
2
解题思路–
先排个序~~
- 1.按照最小值递减的顺序把奶牛排序
- 2.按照防晒霜值递减的顺序把防晒霜排序
然后 举个栗子
代码–
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
int c,l,ans;
struct cl
{
int x,y;
}cc[2505],ll[2505];
bool clc(cl xx,cl yy)
{
return xx.x>yy.x;
}
int main()
{
scanf("%d%d",&c,&l);
for (int i=1;i<=c;++i)
scanf("%d%d",&cc[i].x,&cc[i].y);
for (int i=1;i<=l;++i)
scanf("%d%d",&ll[i].x,&ll[i].y);
sort(cc+1,cc+c+1,clc);
sort(ll+1,ll+l+1,clc);
for (int i=1;i<=c;++i)
for (int j=1;j<=l;++j)
if (ll[j].x>=cc[i].x && ll[j].x<=cc[i].y && ll[j].y)//可以抹
{
ll[j].y--;
ans++;
break;
}
printf("%d",ans);
return 0;
}