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. Atlantis poj1151 线段树扫描线

    Atlantis poj1151 线段树扫描线 题意 题目给了n个矩形,每个矩形给了左下角和右上角的坐标,矩形可能会重叠,求的是矩形最后的面积. 题解思路 这个是我线段树扫描线的第一题,听了学长的讲解 ...

  2. 哪吒票房超复联4,100行python代码抓取豆瓣短评,看看网友怎么说

    <哪吒之魔童降世>这部国产动画巅峰之作,上映快一个月时间,票房口碑双丰收. 迄今已有超一亿人次观看,票房达到42.39亿元,超过复联4,跻身中国票房纪录第三名,仅次于<战狼2> ...

  3. B.Petr and a Combination Lock

    https://codeforces.com/contest/1097/problem/A Petr and a Combination Lock time limit per test 1 seco ...

  4. jQuery中attr()和prop()及removeAttr()和removeProp()的区别

    在jquery1.6之前的所有版本中设置和获取元素属性(固有属性和自定义属性)都使用attr方法,后来单独把设置和获取元素固有属性单独做成了prop()方法. 一般来说: 对于HTML元素本身就带有的 ...

  5. 定时器,定时发邮件JavaMail

    一.定时器用法: 1.1先导入jar包 <!--spring整合其他文件时要用的jar包--> <dependency> <groupId>org.springfr ...

  6. 封装操作mysql、redis

    封装操作mysql: import pymysql class MyDb: def __init__(self,host,password,user,db,port=3306,charset='utf ...

  7. Git命令——提交、查看、后退、前进

    Git常用命令 1. 命令git init把这个目录变成Git可以管理的仓库: 2. 命令git commit把文件提交到仓库 这里需要注意的是,Git只能跟踪文本文件的改动,如txt文件,网页,所有 ...

  8. CF429E Points and Segments

    链接 CF429E Points and Segments 给定\(n\)条线段,然后给这些线段红蓝染色,求最后直线上上任意一个点被蓝色及红色线段覆盖次数之差的绝对值不大于\(1\),构造方案,\(n ...

  9. css 鼠标经过图片缓慢切换图片、鼠标离开缓慢还原

    https://blog.csdn.net/qq_26780317/article/details/80486766 一.控制背景图片在一个圆形div内切换 .header .logo { width ...

  10. Python---基础---dict和set2

    2019-05-21 写一个程序来管理用户登陆系统的用户信息:登陆名字和密码,登陆用户账号建立后,已存在用户可以用登陆名字和密码重返系统,新用户不能用别人的用户名建立用户账号 ------------ ...