Sunscreen
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6410   Accepted: 2239

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; minSPFimaxSPFi ≤ 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
题目大意:具体单词我也不太懂,不过大体意思就是每一只奶牛都有着需要的spf最大值和最小值,然后现在有一些类似防晒霜
可以提供spf,如果一只奶牛被保护,意思就是涂的防晒液提供的spf刚好在要求的最大值和最小值之间,问你最多能保护度多
少只奶牛。
思路分析:目前我只会用贪心做,很显然,需要进行排序,但是是按照最大值还是最小值排序呢,用最小值排序很容易举出反例,
按最大值排序的时候很多情况都是符合的,防晒液按照能够提供的spf从小到大排序是毫无疑问的,然后遍历走一遍就能求出最多
的奶牛数了。
讲道理真让我证明我也不会,但是感觉是这样,也许这就是贪心的精髓吧,在没有其他思路的情况下贪心往往能有奇妙的作用。
另外,要细心!!!内层循环j写成了iwa了四发,555555555555.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int maxn=2500+10;
struct nod
{
    int a;
    int b;
};
nod cow[maxn],s[maxn];
bool cmp1(nod x,nod y)
{
    return x.b==y.b?x.a<y.a:x.b<y.b;
}
bool cmp2(nod x,nod y)
{
    return x.a<y.a;
}
int main()
{
    int c,l;
    int m,n;
    while(scanf("%d%d",&c,&l)!=EOF)
    {
        for(int i=0;i<c;i++)
        {
            scanf("%d%d",&cow[i].a,&cow[i].b);
        }
        for(int i=0;i<l;i++)
        {
            scanf("%d%d",&s[i].a,&s[i].b);
        }
        sort(cow,cow+c,cmp1);
        sort(s,s+l,cmp2);
        int cut=0;
        for(int i=0;i<c;i++)
        {
            for(int j=0;j<l;j++)
            {
                    if(s[j].a>=cow[i].a&&s[j].a<=cow[i].b&&s[j].b>0)
                    {
                        cut++;
                        s[j].b--;
                        break;
                    }
            }
        }
        cout<<cut<<endl;
    }
    return 0;
}

poj3614 贪心的更多相关文章

  1. POJ3614 贪心+优先队列

    题意:m头牛每头牛有minspf和maxspf,n种spf为spf[i]的防晒霜每种l[i]瓶,尽可能给数量多的牛涂防晒霜,每头牛最多涂一瓶. 思路:贪心想法,实现是每次取出minspf<=sp ...

  2. Sunscreen [POJ3614] [贪心]

    描述 C (1 ≤ C ≤ 2500) 头奶牛在海滩边晒太阳,要避免在日光浴时产生难看的灼伤,每头奶牛必须用防晒霜覆盖它的皮肤.第 i 头奶牛有一个最小和最大 SPF 值 (1 ≤ minSPFi ≤ ...

  3. poj3614 Sunscreen(贪心+STL)

    https://vjudge.net/problem/POJ-3614 如果这不是优先队列专题里的,我可能不一定能想到这么做. 结构体命名得有点不好,解题中看着Edge这个不恰当的命名,思路老是断掉. ...

  4. POJ--3614 Sunscreen(贪心)

    题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...

  5. [POJ3614]Sunscreen (贪心)

    题意 (依然来自洛谷) 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常 ...

  6. POJ3614 Sunscreen 贪心入门

    题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1 ...

  7. POJ3614防晒霜 这个贪心有点东西(贪心+优先队列)

    这个题是说有C头牛去晒太阳,带了L瓶防晒霜,每瓶防晒霜都有一个SPF值(每瓶防晒霜都能解决一个最短路 ) 每头牛给出了他可以接受防晒霜的上限,和下限,每种防晒霜都给出了SPF值与数量. 从防晒霜的sp ...

  8. POJ3614奶牛晒阳光DINIC或者贪心

    题意:       n个区间,m种点,每种点有ci个,如果一个点的范围在一个区间上,那么就可以消耗掉一个区间,问最多可以消耗多少个区间,就是这n个区间中,有多少个可能被抵消掉. 思路:       方 ...

  9. 【POJ3614 Sunscreen】【贪心】

    题面: 有c头牛,需要的亮度在[min_ci,max_ci]中,有n种药,每种m瓶,可以使亮度变为v 问最多能满足多少头牛 算法 我们自然考虑贪心,我们首先对每头牛的min进行排序,然后对于每种药,将 ...

随机推荐

  1. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

  2. eclipse项目显示标尺

    Windows-Preferences-General-Editors-Text Editors-Show line numbers

  3. uva 10167 - Birthday Cake

    题解:由于解太多,随机抓 A.B, 只要有符合就行了: (首先,Ax+By=0必须表示直线,即A.B不能同时为0:另外,要注意到直线不能过输入中的2N个点:检测点在直线的哪一侧,只需要简单的线性规划的 ...

  4. nodemon 或者 Supervisor 监控 Express4.x的代码改动

    Express 4.x 默认将启动模块分离到了./bin/www中,直接使用 supervisor/nodemon 无法正常监控应用,使得开发过程中的调试非常不方便.所以我们直接把./bin/www中 ...

  5. 网站UV,与IP、PV

    什么是网站UV,与IP.PV在概念上的区别? UV(独立访客):即Unique Visitor,访问您网站的一台电脑客户端为一个访客.00:00-24:00内相同的客户端只被计算一次. PV(访问量) ...

  6. 关于group by

    <pre name="code" class="sql">关于group by 排序问题 10g 以前sort group by 需要排序 10g ...

  7. 【转】JAVA中的浅拷贝和深拷贝

    原文网址:http://blog.bd17kaka.net/blog/2013/06/25/java-deep-copy/ JAVA中的浅拷贝和深拷贝(shallow copy and deep co ...

  8. Java里的equals总结

    前段时间一直在工作中使用Java,由于有一些C++功底,于是简单看了一下Java相关的语法便开始编写代码,结果在创建一个自定义类,并将自定义类放入ArrayList中,之后查找ArrayList是否有 ...

  9. Java Access Levels(访问控制)

    Access Levels Modifier Class Package Subclass World public Y Y Y Y protected Y Y Y N no modifier Y Y ...

  10. JAVA车票管理系统(简单GUI)

    一.    需求分析 1.设计题目:车票管理系统 用JAVA语言和数据结构知识设计设计车票管理系统.要求如下所述: 一车站每天有n个发车班次,每个班次都有一个班次号(1.2.3…n),固定的发车时间, ...