Sunscreen
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5898   Accepted: 2068

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
 #include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
struct node
{
int a,b;
}cow[],s[];
bool cmp(node x,node y)
{
return x.a<=y.a;
}
int main()
{
int c,l;
int i,j;
priority_queue<int,vector<int>,greater<int> > Q;
freopen("in.txt","r",stdin);
scanf("%d%d",&c,&l);
for(i=;i<c;i++)
scanf("%d%d",&cow[i].a,&cow[i].b);
for(j=;j<l;j++)
scanf("%d%d",&s[j].a,&s[j].b);
sort(cow,cow+c,cmp);
sort(s,s+l,cmp);
j=;
int sum=;
for(i=;i<l;i++)
{
while(j<c&&cow[j].a<=s[i].a)
{
Q.push(cow[j].b);
j++;
}
while(!Q.empty()&&s[i].b)
{
int t=Q.top();
Q.pop();
if(s[i].a<=t)
{
sum++;
s[i].b--;
}
}
}
printf("%d\n",sum);
}

Sunscreen(POJ 3614 优先队列)的更多相关文章

  1. Sunscreen POJ - 3614(贪心)

    To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide with s ...

  2. Heap:Sunscreen(POJ 3614)

    晒太阳 题目大意:一堆牛,为了避免晒太阳会灼烧自己,然后他们自己有自己的防晒指数(一个区间),防晒霜可以提高防晒因数SPF,大了不行小了不行,现在有一桶防晒霜,他们提供一定的SPF,但是最多可以提供k ...

  3. POJ 2431 优先队列

    汽车每过一单位消耗一单位油,其中有给定加油站可加油,问到达终点加油的最小次数. 做法很多的题,其中优先对列解这题是很经典的想法,枚举每个加油站,判断下当前油量是否小于0,小于0就在前面挑最大几个直至油 ...

  4. poj -3614 Sunscreen(贪心 + 优先队列)

    http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...

  5. 【POJ - 3614】Sunscreen (优先队列)

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

  6. POJ 3614:Sunscreen 贪心+优先队列

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5378   Accepted: 1864 Descrip ...

  7. POJ 3614 Sunscreen 优先队列 贪心

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

  8. POJ 3614 Sunscreen (优先队列)

    题意:奶牛美容:有C头奶牛日光浴,每头奶牛分别需要minSPF_i和maxSPF_i单位强度之间的阳光.现有L种防晒霜,分别能使阳光强度稳定为SPF_i,其瓶数为cover_i.求最多满足多少头奶牛 ...

  9. POJ 3614 Sunscreen 贪心

    题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...

随机推荐

  1. Truck History--poj1789

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21534   Accepted: 8379 De ...

  2. Json序列化与反序列化完整实例

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...

  3. 必须弄懂的495个C语言问题

    1.1 我如何决定使用那种整数类型? 如果需要大数 值(大于32, 767 或小于¡32, 767), 使用long 型.否则, 如果空间很重要(如有大数组或很多结构), 使用short 型.除此之外 ...

  4. 《Programming WPF》翻译 第7章 6.视频和3-D

    原文:<Programming WPF>翻译 第7章 6.视频和3-D 虽然详细地讨论视频和3-D超越了这本书的范围,但是获得这些特征的支持是值得的. 视频由MediaElement类型支 ...

  5. VBS 操作注册表 十六进制

    使用VBS操作注册表,通常使用RegRead/RegWrite/RegDelete方法,如: RegRead: 'read.vbs(将以下代码存为read.vbs文件) Dim OperationRe ...

  6. 【转】兼容性测试套件(CTS)框架用户手册

    原文网址:http://blog.sina.com.cn/s/blog_416166e90102v6bi.html 兼容性测试套件(CTS)框架用户手册 1.为什么需要兼容性测试(以下称CTS)? 2 ...

  7. mongodb----修改器

    $inc:增加或者减少指定键值,如果键不存在,就创建一个键. $set:指定一个健的值,如果键不存在,就创建一个键. $unset:删除指定的键. $push:向指定的数组末尾加添加一个元素,如果数组 ...

  8. Game of Life 解答

    Question According to the Wikipedia's article: "The Game of Life, also known simply as Life, is ...

  9. 2016"百度之星" - 资格赛(Astar Round1) 1004

    思路:题目很简单,直接用map记录每个字符串的个数就可以了.记得对每个字符串先sort(). AC代码: #include <cstdio> #include <stdlib.h&g ...

  10. mount命令汇总(转载)

    (一)挂接命令(mount) 首先,介绍一下挂接(mount)命令的使用方法,mount命令参数非常多,这里主要讲一下今天我们要用到的. 命令格式: mount [-t vfstype] [-o op ...