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 ...
随机推荐
- 使用命令修改ip地址
简述:以serverv 2012 r2为例 常用的几种,当然不全,希望能较快的速率记下一种便可 直接配置 1. 查看网卡的显示名称 2. 配置静态iP地址 3. 查看配置 ...
- cocos2dx2.2.2弹出框的实现
在上一篇文章中,我们利用CCEditBox实现了输入框功能,使我们在注册时可以输入用户名和密码.但是当用户名和密码的输入不符合规范时,我们应该怎样给与用户提示呢?下面我们就来介绍弹出框的实现方式. 我 ...
- PHP 布尔类型
PHP 布尔类型 布尔类型 这是最简单的类型.boolean 表达了真值,可以为 TRUE 或 FALSE. Note: 布尔类型是 PHP 4 引进的. 语法 要指定一个布尔值,使用关键字 TRUE ...
- WebServiceException
在用cxf做webservice的时候,在写客户端程序的时候,出现以下异常: Could not find wsdl:binding operation info for web method tes ...
- wiegand 问题
在向门控器发送信号的时候,播放声音和通过GPIO向wiegand发送信号的时候,由于wiegand的资源优先级别不够和声音的播放可能发生了冲突,有时向GPIO发送信号的时候,发送失败. static ...
- Python深拷贝和浅拷贝
1- Python引用计数[1] 1.1 引用计数机制 引用计数是计算机编程语言中的一种内存管理技术,是指将资源(可以是对象.内存或磁盘空间等等)的被引用次数保存起来,当被引用次数变为零时就将其释放的 ...
- 生成HTMLTestRunner测试报告的操作步骤——Python+selenium自动化
HTMLTestRunner是Python标准库的unittest模块的一个扩展,具体操作如下 1.安装 环境:Window8 步骤:1)http://tungwaiyip.info/software ...
- OOA、OOD、OOP
复习 OOA.OOD.OOP OOA Object-Oriented Analysis:面向对象分析方法 是在一个系统的开发过程中进行了系统业务调查以后,按照面向对象的思想来分析问题.OOA与结构 ...
- Microsoft.Xna.Framework.TitleContainer.OpenStream()
/// <summary> /// This method opens a file using System.IO classes and the /// TitleLocation p ...
- LINQ技巧:如何通过多次调用GroupBy实现分组嵌套
问题如上,解决如下,目标在最下面:结果: using System; using System.Linq; using System.Collections.Generic; namespace Co ...