poj3614Sunscreen 贪心

题目

To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide with sunscreen when they’re at the beach. Cow i has a minimum and maximum SPF rating (1 ≤ minSPFi ≤ 1,000; minSPFi ≤ maxSPFi ≤ 1,000) that will work. If the SPF rating is too low, the cow suffers sunburn; if the SPF rating is too high, the cow doesn’t tan at all……..

The cows have a picnic basket with L (1 ≤ L ≤ 2500) bottles of sunscreen lotion, each bottle i with an SPF rating SPFi (1 ≤ SPFi ≤ 1,000). Lotion bottle i can cover coveri cows with lotion. A cow may lotion from only one bottle.

What is the maximum number of cows that can protect themselves while tanning given the available lotions?
有C头奶牛日光浴,第i头奶牛需要minSPF[i]和maxSPF[i]单位强度之间的阳光。每头奶牛在日光浴之前必须涂防晒霜,防晒霜有L种,涂上第i种之后,身体接收到的阳光强度就会稳定为SPF[i],第i种防晒霜有cover[i]瓶。求最多可以满足多少头奶牛进行日光浴。C,L<=2500

题解

贪心
对minSPF递减排序,排序后对于每头奶牛,找一个它能用的SPF最大的防晒霜给它用。
因为排序后一头奶牛后面的奶牛minSPF一定不比他大,那么给当前奶牛用SPF大的防晒霜对整体问题的影响要比用SPF小的防晒霜要好

代码

#include <cstdio>
#include <algorithm>

using namespace std;

const int N=2503;
int n,m,ans;
int s[1003];
struct node{
    int a,b;
}f[N];

bool comp(node a,node b){
    return a.a>b.a;
}

int main(){
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        scanf("%d%d",&f[i].a,&f[i].b);
    for (int i=1;i<=m;i++){
        int c,w;
        scanf("%d%d",&c,&w);
        s[c]+=w;
    }
    sort(f+1,f+n+1,comp);
    for (int i=1;i<=n;i++){
        for (int j=f[i].b;j>=f[i].a;j--)
            if (s[j]){
                ans++,s[j]--;
                break;
            }
    }
    printf("%d",ans); 
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值