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. hdu 1711 Number Sequence(KMP模板题)

    我的第一道KMP. 把两个数列分别当成KMP算法中的模式串和目标串,这道题就变成了一个KMP算法模板题. #include<stdio.h> #include<string.h> ...

  2. [Mugeda HTML5技术教程之11]Mugeda API简介

    一.API 概述 Mugeda API 提供了一个简单的,结构化的方法来实时动态管理Mugeda内容.它提供了一下方法: •访问Mugeda内容中的对象. •获取和设置对象属性,如位置.旋转.比例.不 ...

  3. 使用PHP解压文件Unzip

    这是一个非常方便的PHP函数从.zip文件解压缩文件.它有两个参数:第一个是压缩文件的路径和第二 function unzip_file($file, $destination) { // creat ...

  4. jquery1.9学习笔记 之选择器(基本元素五)

    多种元素选择器  jQuery("selector1,selector2,selectorN") 例子: <!doctype html> <html lang=' ...

  5. Flask学习记录之Flask-Moment

    Moment.js 是一个简单易用的轻量级JavaScript日期处理类库,提供了日期格式化.日期解析等功能.它支持在浏览器和NodeJS两种环境中运行.此类库能够 将给定的任意日期转换成多种不同的格 ...

  6. DataTables列过滤器

    var table = $('#example').DataTable(); table.columns().flatten().each( function ( colIdx ) { // Crea ...

  7. UILabel自适应高度和自动换行

    码: //初始化label UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)]; //设置自动行数与字符换行 [l ...

  8. 郁闷~win7无法进行局域网访问解决

    win7无法进行局域网访问解决 公司里经常会使用网络共享的文件服务器,但是用win7的那伙计,在输入帐号和密码后却提示密码错误,试验了多次都是如此. 经过网上搜索文章及自己的研究最后发现这是由于win ...

  9. NOI2013 树的计数

    题目:http://uoj.ac/problem/122 85%做法: 动态规划. 首先重编号,BFS序变成1...n,然后DFS序相应重编号. 记pos[i]为i号点在DFS中的位置,即pos[d[ ...

  10. spring与数据库之间的配置

    spring 配置数据源的三种方式 1.使用org.springframework.jdbc.datasource.DriverManagerDataSource配置文件: <bean id=& ...