POJ 3614 Sunscreen 贪心
题目链接:
http://poj.org/problem?id=3614
Sunscreen
Time Limit: 1000MSMemory Limit: 65536K
#### 问题描述
> 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?
输入
- 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
输出
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头牛晒太阳,每头牛都有一个能承受辐射的范围(min~max),现在有 l 种防晒霜,每种防晒霜都能将辐射值固定在spf,每种防晒霜都有一定的数量num。每头牛用最多一种防晒霜,问能满足多少头牛。
题解
贪心
对所有的牛按左端点排序,最所有的防晒霜按其spf值排序,然后从小到大枚举防晒霜,枚举到第i个防嗮霜的时候在所有可以满足的牛里面贪心选出一个右端点最小的牛(它最不可能用到后面的防嗮霜,所有他优先选)。
代码
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<functional>
#define X first
#define Y second
#define mp make_pair
using namespace std;
const int maxn = 2555;
int n, m;
struct Node {
int x, y;
Node(int x,int y):x(x),y(y){}
bool operator < (const Node& tmp) const {
return y > tmp.y;
}
};
vector<pair<int, int> > cow, sc;
int main() {
while (scanf("%d%d", &n, &m) == 2 && n) {
cow.clear(); sc.clear();
for (int i = 0; i < n; i++) {
int x, y; scanf("%d%d", &x, &y);
cow.push_back(mp(x, y));
}
for (int i = 0; i < m; i++) {
int x, y; scanf("%d%d", &x, &y);
sc.push_back(mp(x, y));
}
sort(cow.begin(), cow.end());
sort(sc.begin(), sc.end());
int ans = 0,st=0;
priority_queue<Node> pq;
for (int i = 0; i < m; i++) {
while (st < n&&cow[st].X <= sc[i].X) {
pq.push(Node(cow[st].X, cow[st].Y));
st++;
}
while (!pq.empty() && sc[i].Y) {
if (sc[i].X <= pq.top().y) {
sc[i].Y--;
ans++;
}
pq.pop();
}
}
printf("%d\n", ans);
}
return 0;
}
POJ 3614 Sunscreen 贪心的更多相关文章
- 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值和容量(能供几头 ...
- Sunscreen POJ - 3614(贪心)
To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide with s ...
- 优先队列:POJ No 3614 Sunscreen 贪心
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6410 Accepted: 2239 Descrip ...
- POJ 3614 Sunscreen(贪心,区间单点匹配)
把牛的SPF看作一个区间,防晒霜看作点.一个点可以匹配C[i]次,问最大匹配数.可以用图论做. 也可以贪心.贪心的思想是,把区间和点排序以后,考虑最左边的点,加入和这个点相交的区间, 并排除出界的区间 ...
- POJ 3614 Sunscreen 优先队列 贪心
题意 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常大,奶牛都承受不住 ...
- poj 3614 Sunscreen
...
- POJ 3614 Sunscreen (优先队列)
题意:奶牛美容:有C头奶牛日光浴,每头奶牛分别需要minSPF_i和maxSPF_i单位强度之间的阳光.现有L种防晒霜,分别能使阳光强度稳定为SPF_i,其瓶数为cover_i.求最多满足多少头奶牛 ...
- POJ 3614:Sunscreen 贪心+优先队列
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5378 Accepted: 1864 Descrip ...
随机推荐
- openquery链表删除时报错 “数据提供程序或其他服务返回 E_FAIL 状态”
DELETE OPENQUERY (VERYEAST_COMPANY_MYSQL_CONN, 'SELECT * FROM company ') WHERE c_userid in(select c_ ...
- Apache2.4 与 PHP 5.5 64位版的安装配置
我的环境:windows7 旗舰版 64位 首先下载相关文件: php 5.5.0 windows 64版 http://windows.php.net/download/#php-5.5 (选择 6 ...
- Firebug 调试技巧之console API
console.log(object[, object, ...]) Writes a message to the console. You may pass as many arguments a ...
- 细说SQL 连接
连接条件可在FROM或WHERE子句中指定,建议在FROM子句中指定连接条件.WHERE和HAVING子句 也可以包含搜索条件,以进一步筛选连接条件所选的行. ...
- Python 字典(Dictionary) setdefault()方法
描述 Python 字典(Dictionary) setdefault() 函数和get()方法类似, 如果键不已经存在于字典中,将会添加键并将值设为默认值. 语法 setdefault()方法语法: ...
- python基础:三元运算
学习条件运算时,对于简单的 if else 语句,可以使用三元运算来表示,即: 1 2 3 4 5 6 7 8 # 普通条件语句 if 1 == 1: name = 'wupeiqi' els ...
- TreeView控件的CheckBox级联选中或取消
背景: 在一个项目开发中遇到这样的要求:当选中树中一个节点时,需要同时选中其父节点,直至根节点.在取消一个节点的选中时,需要将其所有子节点取消选中,直至叶子节点.由于项目用户体验暂时可以不用考虑,直接 ...
- Stack Overflow 2016最新架构探秘
这篇文章主要揭秘 Stack Overflow 截止到 2016 年的技术架构. 首先给出一个直观的数据,让大家有个初步的印象. 相比于 2013 年 11 月,Stack Overflow 在 20 ...
- 8款HTML5动画特效推荐源码
1.HTML5 Canvas发光Loading动画 之前我们分享过很多基于CSS3的Loading动画效果,相信大家都很喜欢.今天我们要来分享一款基于HTML5 Canvas的发光Loading加载动 ...
- 【转】Javascript 中的false,零值,null,undefined和空字符串对象
js 开发中经常会碰到判断是否为空的情况,关于 null 和 undefined 的区别了解的不是很好,刚好看见这篇文章,转过来学习一下,以下是转载正文: 在Javascript中,我们经常会接触到题 ...