• POJ 3614-Sunscreen


    Description

    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?

    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
    Source

    USACO 2007 November Gold
    .
    .
    .
    .
    .
    .

    分析

    只用排序然后直接贪心
    .
    .
    .
    .
    .

    程序:
    #include<iostream>
    using namespace std;
    int minspf[2501],maxspf[2501],spf[2501],cover[2501],c,l1;
    
    void kp1()
    {
        int cao;
        for (int i=1;i<=c-1;i++)
        {
            for (int j=i+1;j<=c;j++)
            if (maxspf[j]<maxspf[i]||maxspf[i]==maxspf[j]&&maxspf[j]<=maxspf[i])
            {
                cao=minspf[i];minspf[i]=minspf[j];minspf[j]=cao;
                cao=maxspf[i];maxspf[i]=maxspf[j];maxspf[j]=cao;
            }
        }
    }
    
    void kp2(int l,int r)
    {
        if (l>=r) return;
        int i=l,j=r,mid=spf[(l+r)/2],cao;
        do
        {
            while (spf[i]<mid) i++;
            while (spf[j]>mid) j--;
            if (i<=j)
            {
                cao=spf[i];spf[i]=spf[j];spf[j]=cao;
                cao=cover[i];cover[i]=cover[j];cover[j]=cao;
                i++;j--;
            }
        }while (i<=j);
        kp2(l,j);
        kp2(i,r);
    }
    
    int main()
    {
        cin>>c>>l1;
        for (int i=1;i<=c;i++)
        cin>>minspf[i]>>maxspf[i];
        for (int i=1;i<=l1;i++)
        cin>>spf[i]>>cover[i];
        kp1();
        kp2(1,l1);
        int tj=0;
        for (int i=1;i<=c;i++)
        {
            for (int j=1;j<=l1;j++)
            {
                if (spf[j]>maxspf[i]) break;
                if (minspf[i]<=spf[j]&&spf[j]<=maxspf[i]&&cover[j])
                {
                    tj++;
                    cover[j]--;
                    break;
                }
            }
        }
        cout<<tj;
        return 0;
    }
  • 相关阅读:
    SpringBoot08-缓存
    Spring注解-自动装配(三)
    Spring注解-生命周期与属性赋值(二)
    Spring注解-组件注册(一)
    剖析SpringMVC流程与整合(八)
    SpringMVC视图解析与配置(六)
    SpringMVC的其他功能(七)
    简单了解SpringMVC(五)
    Java动态代理
    Spring事务(四)
  • 原文地址:https://www.cnblogs.com/YYC-0304/p/9499904.html
Copyright © 2020-2023  润新知