题目链接:

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. 异常getaddrinfo enotfound

    在看NodeJS开发指南这本书时,书中的一个例子,讲解http.request的.代码如下: var http = require('http'); var querystring = require ...

  2. (转)mongodb常用命令脚本化-自动化运维

    mongodb常用命令脚本化-自动化运维 把一些运维中常用到的mongodb命令写成shell脚本,极大的方便了维护   1 设置副本集   #!/bin/bash#mongodb 进入client ...

  3. unity基本操作二

    一:error1,先断网再启动点击Manual Activation点击Save License生成相应的alf文件2,联网打开https://license.unity3d.com/manual上传 ...

  4. CustomMessageBox使用总结

    开发过程中难免要使用到消息框,然而系统提供的MessageBox却难以满足许多需求.一.MessageBox的背景颜色无法更改,这就无法满足需求要求的消息框颜色.二.MessageBox的提示形式过于 ...

  5. <Linux系统hostname命令详解>

    hostname命令的用法的小知识我们都知道hostname命令是查看主机名和修改主机名的. [root@apache ~]# hostname  //查看本机的主机名apache.example.c ...

  6. Ubuntu16.04.1 安装Redis-Cluster

    Redis在3.0版正式引入了集群这个特性.Redis集群是一个分布式(distributed).容错(fault-tolerant)的 Redis内存K/V服务, 集群可以使用的功能是普通单机 Re ...

  7. 重拾C,一天一点点_4_随想

    刚才顺便又把二分默写了一遍,还好,这次比较顺利.算法这一块,一直是自己一块痛处,有时感觉自己的脑瓜子怎么就这么笨,后一想觉得肯定是锈逗了,确实啊,这么长时间不思考的脑子能机灵到哪呢?早就意识到这个问题 ...

  8. Session原理简述

    Session存在的意义,估计每个用做web开发的人都是了解的,就为了解决HTTP是个无状态协议所带来的问题,不多说了.这里主要想说的是服务端与客户端是如何利用session进行交互的. Sessio ...

  9. WPF:实现主应用程序单一实例运行方式总结

       本文介绍常见的实现主应用程序单一实例运行的几种方式. 方式一: public partial class App : Application { protected override void ...

  10. oracle11g关于表空间的问题

    1.oracle11g默认的块大小为8K  每个表空间里面的单个数据文件最大为32G   (2^22-1) *4k   最多可以放1024个单个文件    SQL> show parameter ...