题目链接:

http://poj.org/problem?id=3614

Sunscreen

Time Limit: 1000MS
Memory 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 贪心的更多相关文章

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

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

  2. 【POJ 3614 Sunscreen】贪心 优先级队列

    题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...

  3. Sunscreen POJ - 3614(贪心)

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

  4. 优先队列:POJ No 3614 Sunscreen 贪心

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6410   Accepted: 2239 Descrip ...

  5. POJ 3614 Sunscreen(贪心,区间单点匹配)

    把牛的SPF看作一个区间,防晒霜看作点.一个点可以匹配C[i]次,问最大匹配数.可以用图论做. 也可以贪心.贪心的思想是,把区间和点排序以后,考虑最左边的点,加入和这个点相交的区间, 并排除出界的区间 ...

  6. POJ 3614 Sunscreen 优先队列 贪心

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

  7. poj 3614 Sunscreen

                                                                                                        ...

  8. POJ 3614 Sunscreen (优先队列)

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

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

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

随机推荐

  1. jquery 中如何将数组转化为json字符串,然后再转化回来?

    其实可以这样: $.fn.stringify = function() { return JSON.stringify(this); } 然后这样调用: $(array).stringify(); 转 ...

  2. ASP.Net 类(CS)文件怎样获取Web应用程序的路径

    Web应用程序,写了一个线程CS类别,这个类别将会放于Global.asax文件中执行,主要是监控程序下某一个文件是否有异动,而作出相应警示动作,如发送邮件等. 实现运行过程中,也许会有一个情况出现, ...

  3. cocos2dx2.2.2弹出框的实现

    在上一篇文章中,我们利用CCEditBox实现了输入框功能,使我们在注册时可以输入用户名和密码.但是当用户名和密码的输入不符合规范时,我们应该怎样给与用户提示呢?下面我们就来介绍弹出框的实现方式. 我 ...

  4. 【学习笔记】【C语言】类型说明符

    1. short和long 1> short和long可以提供不同长度的整型数,也就是可以改变整型数的取值范围.在64bit编译器环境下,int占用4个字节(32bit),取值范围是-231~2 ...

  5. linux 系统运行级别及修改[转]

    Linux运行级别从0-6,共7个. 0:关机.不能将系统缺省运行级别设置为0,否则无法启动. 1:单用户模式,只允许root用户对系统进行维护. 2:多用户模式,但不能使用NFS(相当于Window ...

  6. HDU1070 Milk 细节决定成败

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1070 注意:1.喝到第五天,第六天就不喝了  2.相同花费的,优先考虑容量大的  3.注意强制类型转换 ...

  7. Java一些常见的出错异常处理

    一些平时常见的错误及解决办法,我 是新手,每次遇到的错误都记录了下来. 1. 404错误 description The requested resource (/Struts2_0100_Intro ...

  8. Codevs 1010 过河卒

     时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 如图,A 点有一个过河卒,需要走到目标 B 点.卒行走规则:可以向下.或者向右.同 ...

  9. CPU卡及NFC供应商

    1.苏州市民卡供应商 北京握奇数据/watchdata 2.苏州市民卡手表 苏州连爱/linklove公司 3.NFC供应商 英飞凌/Infelion, NXP,复旦微电子, 4.什么是CPU卡? C ...

  10. C++中extern “C”含义深层探索

    C++中extern “C”含义深层探索 extern “C” 是一个双向都需要用到的语法表示,就是说在cpp引用c头文件,或者c引用cpp文件时都需要用到.但extern “C” 永远只能在cpp引 ...