poj 3614 Sunscreen
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7450 | Accepted: 2627 |
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 题意:有C头牛晒太阳,每头牛都有相应的SPF范围,在范围内可以让牛享受太阳,有L瓶防晒霜,每瓶防晒霜都有各自的SPF值,SPF值在某头牛的SPF范围内的防晒霜如果涂在该牛上,可以让该牛享受太阳,问有多少头牛可以享受太阳。
思路:贪心,对于每一种防晒霜,在符合条件的范围内(防晒霜的SPF值大于牛的min_SPF),每次都筛选出一群牛,将这群牛的max_SPF值压入最小堆,之后尽量用SPF值较小的防晒霜涂于max_SPF较小的牛上。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<queue>
#include<algorithm>
#include<functional>//greater
using namespace std;
const int N_MAX = ;
struct cows {
int low;
int high;
bool operator <(const cows&b)const{
return low<b.low||(low==b.low&&high<b.high);
}
};
struct lotion {
int spf;
int num;
bool operator <(const lotion&b)const {
return spf <b.spf ;
}
};
priority_queue<int,vector<int>,greater<int>>que;//小元素在上
cows cow[N_MAX];
lotion lo[N_MAX];
int main() {
int C, L;
scanf("%d%d",&C,&L);
for (int i = ;i < C;i++)
scanf("%d%d", &cow[i].low, &cow[i].high);
for (int i = ;i < L;i++)
scanf("%d%d", &lo[i].spf, &lo[i].num);
sort(cow, cow + C);//按牛的spf最小值从小到大排序
sort(lo, lo + L);//按护肤品的spf值从小到大排
int result=,cur=;
for (int i = ;i < L;i++) {//对于每一种护肤品进行考虑
while (cur<C&&lo[i].spf>=cow[cur].low) {//挑选出满足条件的牛的high值进堆
que.push(cow[cur].high);//进堆后小的high值在上面
cur++;
}
while (que.size() && lo[i].num) {//如果这种护肤品对所有挑选出来的牛都不满足条件,那么只能弃用,因为后面的牛的min值都比护肤品的spf大
int k = que.top();que.pop();
if (k >= lo[i].spf) {//high值小于护肤品的spf值的牛只能不涂,后面的护肤品spf值越来越大更不满足
result++;
lo[i].num--;
}
}
}
printf("%d\n",result);
return ; }
poj 3614 Sunscreen的更多相关文章
- POJ 3614 Sunscreen 贪心
题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...
- poj -3614 Sunscreen(贪心 + 优先队列)
http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...
- 【POJ 3614 Sunscreen】贪心 优先级队列
题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...
- POJ 3614 Sunscreen 优先队列 贪心
题意 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常大,奶牛都承受不住 ...
- POJ 3614 Sunscreen (优先队列)
题意:奶牛美容:有C头奶牛日光浴,每头奶牛分别需要minSPF_i和maxSPF_i单位强度之间的阳光.现有L种防晒霜,分别能使阳光强度稳定为SPF_i,其瓶数为cover_i.求最多满足多少头奶牛 ...
- POJ 3614 Sunscreen(贪心,区间单点匹配)
把牛的SPF看作一个区间,防晒霜看作点.一个点可以匹配C[i]次,问最大匹配数.可以用图论做. 也可以贪心.贪心的思想是,把区间和点排序以后,考虑最左边的点,加入和这个点相交的区间, 并排除出界的区间 ...
- 【POJ 3614】 Sunscreen
[题目链接] http://poj.org/problem?id=3614 [算法] 将MinSPF从大到小排序,每头牛找SPF值最大的防晒霜 [代码] #include <algorithm& ...
- Sunscreen(POJ 3614 优先队列)
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5898 Accepted: 2068 Descrip ...
- Sunscreen POJ - 3614(贪心)
To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide with s ...
随机推荐
- 关于java的JIT知识
1.JIT的工作原理图 工作原理 当JIT编译启用时(默认是启用的),JVM读入.class文件解释后,将其发给JIT编译器.JIT编译器将字节码编译成本机机器代码. 通常javac将程序源码编译, ...
- thinkphp模板中使用自定义函数
注意:自定义函数要放在项目应用目录/common/common.php中. 这里是关键. 模板变量的函数调用格式:{$varname|function1|function2=arg1,arg2,### ...
- LINUX 内核文档地址
Linux的man很强大,该手册分成很多section,使用man时可以指定不同的section来浏览,各个section意义如下: 1 - commands2 - system calls3 - l ...
- Python_爬虫1
Urllib库的基本使用 那么接下来,小伙伴们就一起和我真正迈向我们的爬虫之路吧. 1.分分钟扒一个网页下来 怎样扒网页呢?其实就是根据URL来获取它的网页信息,虽然我们在浏览器中看到的是一幅幅优美的 ...
- UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)
Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people e ...
- Direct3D-3 四元数
其实本来这篇文章是打算接上篇的各种变化矩阵的推导了,想了想,还是先讲四元数吧.本人的文章并不会提到欧拉角,因为我自己没弄懂欧拉角的万向锁问题. 很多人学习数学时,会有这样一个疑惑,这东 ...
- Android(java)学习笔记69:JDK5之后的Lock锁的概述和使用
1. Lock锁的概述: java.util.concurrent.locks,接口Lock 首先Lock是一个接口,Lock实现提供了比使用synchronized方法 和 同步代码块更为广泛的锁定 ...
- 3.4.2内核下的I2C驱动
1. 框架1.1 硬件协议简介1.2 驱动框架1.3 bus-drv-dev模型及写程序a. 设备的4种构建方法a.1 定义一个i2c_board_info, 里面有:名字, 设备地址 然后i2c_r ...
- Linux下VirtualBox出现kernel driver not installed的解决方法
今天安装好rhel-server-6.6-i386后,再安装VirtualBox成功,但是再VirtualBox中创建虚拟机的时候出现了“不能为xx虚拟机打开新任务” 并弹出如下的错误信息:
- 【策略】UVa 278 - Chess
Chess Almost everyone knows the problem of putting eight queens on an chessboard such that no Quee ...