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

现附上AC代码:

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int cmp(pair<int ,int > a,pair<int ,int >b){
if(a.first==b.first) return a.second<b.second;
else return a.first<b.first;
}
int main(){
int C,L;
cin>>C>>L;
pair<int ,int > c[2510],va[2510];
for(int i=0;i<C;i++)
scanf("%d%d",&c[i].first,&c[i].second);
for(int j=0;j<L;j++)
scanf("%d%d",&va[j].first,&va[j].second);
priority_queue<int ,vector<int >,greater<int > >q;
sort(c,c+C,cmp);
sort(va,va+L,cmp);
int k=0,sum=0;
for(int i=0; i<L; i++){
while(k < C && c[k].first <= va[i].first){
q.push(c[k].second); k++;
}
while( !q.empty() && va[i].second)
{
int m = q.top();
q.pop();
if(m >= va[i].first) sum++,va[i].second--;
}
}
printf("%d",sum);
return 0;
}

思路:将两个数组的数据从小到大进行排序,

从最小的防晒霜枚举,将所有符合 防晒度的最小值小于等于该防晒霜的奶牛 最大值放入优先队列之中。然后优先队列是小值先出所以就可以将这些最大值中的最小的取出来。更新答案。

整体思路:防晒霜(由小到大)肯定是最先供给给最大值最小的奶牛,防止以后其他防晒霜闲置;

poj3614Sunscreen的更多相关文章

  1. 【优先队列】POJ3614-Sunscreen

    参考:❀ #include<iostream> #include<cstdio> #include<queue> #include<algorithm> ...

随机推荐

  1. 埃及分数问题(带乐观估计函数的迭代加深搜索算法-IDA*)

    #10022. 「一本通 1.3 练习 1」埃及分数 [题目描述] 在古埃及,人们使用单位分数的和(形如 $\dfrac{1}{a}​$​​ 的,$a$ 是自然数)表示一切有理数.如:$\dfrac{ ...

  2. 网页中<a>标签新窗口和location.href 新窗口打开

    在网页制作过程中,经常遇到新窗口打开,一般是a超级链接或者location.href 新窗口打开形式,下面分别讲述两种之间的不同方式 1,a标签 新窗口 添加属性 target="_blan ...

  3. app防攻击办法

    方法一 要求请求端带上一个随机字符串state(也可以是特定规则生成的,甚至是从服务器上请求过来的),服务端(用过滤/拦截器之类的实现不会影响业务代码)收到之后缓存一定的时间(长短视业务和硬件),每次 ...

  4. C#传特定的值,获得特定的数组排序

    一,在实际业务中,我们会有当我们传任何值进来时,我们要有特定的排序,,比如传进来的是"生物", "历史","化学", 但实际上我们需要的是& ...

  5. python学习笔记(11):文件的访问与函数式编程

    一.文本文件读写的三种方法 1.直接读入 file1 = open('E:/hello/hello.txt') file2 = open('output.txt','w') #w是可写的文件 whil ...

  6. Latex--入门系列二

    Latex 专业的参考 tex对于论文写作或者其他的一些需要拍版的写作来说,还是非常有意义的.我在网上看到这个对于Latex的入门介绍还是比较全面的,Arbitrary reference.所以将会翻 ...

  7. JavaScript高级笔记

    # 今日内容:     1. JavaScript:         1. ECMAScript:         2. BOM:         3. DOM:             1. 事件 ...

  8. vue中对于图片是否正常加载的思考

    问题:由于业务需要,我们需要判断图片能否正常的加载,如果未正常加载的话,需要显示一张默认图片: 方案:1,由于后台返回的是一个图片id数组,例如 imgList=['343313131','21333 ...

  9. 【转】SPI FLASH与NOR FLASH的区别 详解SPI FLASH与NOR FLASH的不一样

    转自:http://m.elecfans.com/article/778203.html 本文主要是关于SPI FLASH与NOR FLASH的相关介绍,并着重对SPI FLASH与NOR FLASH ...

  10. pwd 显示当前所在的工作路径

    1.功能说明 pwd命令是“print working directory ”首字母缩写,显示当前目录的绝对路径. 2.语法格式 pwd [option] pwd 选项 3.命令参数 参数 参数说明 ...