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. HihoCoder - 1093 小Hi和小Ho (SPFA)

    描述 万圣节的晚上,小Hi和小Ho在吃过晚饭之后,来到了一个巨大的鬼屋! 鬼屋中一共有N个地点,分别编号为1..N,这N个地点之间互相有一些道路连通,两个地点之间可能有多条道路连通,但是并不存在一条两 ...

  2. Vert.x学习第一天

    昨天看了下异步,然后就开始了Vert.x相关知识的学习. Vert.x是当下非常流行的一套全异步框架,其优势在于轻量级.高效.非常适合作为移动端后台或是企业应用. 当然对于第一天接触这个框架的人(没错 ...

  3. CSS制作垂直口风琴2

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 什么是dockerfile?

    什么是dockerfile? Dockerfile是一个包含用于组合映像的命令的文本文档.可以使用在命令行中调用任何命令. Docker通过读取Dockerfile中的指令自动生成映像. docker ...

  5. Webpack和Gulp对比

    Webpack和Gulp对比 作者 彬_仔 关注 2016.10.19 22:42* 字数 8012 阅读 2471评论 18喜欢 68 在现在的前端开发中,前后端分离.模块化开发.版本控制.文件合并 ...

  6. VUE:v-for获取列表前n个数据、中间范围数据、末尾n条数据的方法

    说明: 1.开发使用的UI是mintUI, 要求: 1.获取6到13之间的数据:items.slice(6,13) <mt-cell v-for="(item,index) in it ...

  7. ideamaven版的MBG逆向工程

    一.简介 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的根据表生成对应的映射文件,接口,以及bean类. 支持基本的增删改查,以及QBC风格的条件查询. 但是表连接.存储 ...

  8. Flask 之装饰器有关

    - 先记住一句话:自定义python装饰器时一定要记住使用@functools.wraps(func)修饰wrapper - 在Flask中使用装饰器遇到AssertionError: View fu ...

  9. datatables屏蔽警告弹窗

    //不显示任何错误信息 $.fn.dataTable.ext.errMode = 'none'; //以下为发生错误时的事件处理,如不处理,可不管. $('#tableId').on( 'error. ...

  10. HashMap测试程序2

    package com.iotek.map; import java.util.HashMap;import java.util.Map; public class HashMapDemo2 { /* ...