zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    luoguP1160 队列安排 x
    luoguP3366 【模板】最小生成树 x
    cogs服务点设置(不凶,超乖) x
    codevs3269 混合背包 x
    [kuangbin带你飞]专题一 简单搜索 x
    [SWUST1744] 方格取数问题(最大流,最大独立集)
    [SWUST1738] 最小路径覆盖问题(最大流,最小路径覆盖)
    [SWUST1742] 试题库问题(最大流)
    [HDOJ5676]ztr loves lucky numbers(状压枚举,打表,二分)
    [swustoj1739] 魔术球问题 (最大流,最小路径覆盖)
  • 原文地址:https://www.cnblogs.com/YYC-0304/p/9499904.html
Copyright © 2011-2022 走看看