题目链接:

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个防嗮霜的时候在所有可以满足的牛里面贪心选出一个右端点最小的牛(它最不可能用到后面的防嗮霜,所有他优先选)。

代码

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #include<algorithm>
  5. #include<queue>
  6. #include<functional>
  7. #define X first
  8. #define Y second
  9. #define mp make_pair
  10. using namespace std;
  11. const int maxn = 2555;
  12. int n, m;
  13. struct Node {
  14. int x, y;
  15. Node(int x,int y):x(x),y(y){}
  16. bool operator < (const Node& tmp) const {
  17. return y > tmp.y;
  18. }
  19. };
  20. vector<pair<int, int> > cow, sc;
  21. int main() {
  22. while (scanf("%d%d", &n, &m) == 2 && n) {
  23. cow.clear(); sc.clear();
  24. for (int i = 0; i < n; i++) {
  25. int x, y; scanf("%d%d", &x, &y);
  26. cow.push_back(mp(x, y));
  27. }
  28. for (int i = 0; i < m; i++) {
  29. int x, y; scanf("%d%d", &x, &y);
  30. sc.push_back(mp(x, y));
  31. }
  32. sort(cow.begin(), cow.end());
  33. sort(sc.begin(), sc.end());
  34. int ans = 0,st=0;
  35. priority_queue<Node> pq;
  36. for (int i = 0; i < m; i++) {
  37. while (st < n&&cow[st].X <= sc[i].X) {
  38. pq.push(Node(cow[st].X, cow[st].Y));
  39. st++;
  40. }
  41. while (!pq.empty() && sc[i].Y) {
  42. if (sc[i].X <= pq.top().y) {
  43. sc[i].Y--;
  44. ans++;
  45. }
  46. pq.pop();
  47. }
  48. }
  49. printf("%d\n", ans);
  50. }
  51. return 0;
  52. }

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. 【网络收集】如何修改vs tfs的登录名和密码 .

    连接TFS时,如果本机保存了用户的网络密码,不会出现用户名和密码的输入框,若要更换TFS的用户名和密码,需按以下步骤操作:控制面板--->用户账号--->管理网络密码,此时会列出所有保存了 ...

  2. 【学习笔记】【C语言】进制

    1. 什么是进制 是一种计数的方式,数值的表示形式 2. 二进制 1> 特点:只有0和1,逢2进1 2> 书写格式:0b或者0b开头 3> 使用场合:二进制指令\二进制文件,变量在内 ...

  3. Engine许可初始化 - gis开发初步

    当需要对SDE中的要素类和要素数据集(矢量和栅格)进行编辑时,例如在调用IFeatureDataset的CreateFeatureClass方法时,报错提示: The application is n ...

  4. zz linux 下查看局域网内所有存活主机和MAC进址

    用namp对局域网扫描一遍,然后查看arp缓存表就可以知道局域内ip-mac的对应了namp比较强大也可以直接扫描mac地址和端口 进行ping扫描,打印出对扫描做出响应的主机: nmap -sP 1 ...

  5. 利用word2vec对关键词进行聚类

    1.收集预料 自己写个爬虫去收集网页上的数据. 使用别人提供好的数据http://www.sogou.com/labs/dl/ca.html 2.对预料进行去噪和分词 我们需要content其中的值, ...

  6. Linux读写锁的使用

    读写锁是用来解决读者写者问题的,读操作可以共享,写操作是排它的,读可以有多个在读,写只有唯一个在写,写的时候不允许读. 具有强读者同步和强写者同步两种形式: 强读者同步:当写者没有进行写操作时,读者就 ...

  7. 理解ClassLoader基本原理

    当JVM(Java虚拟机)启动时,会形成由三个类加载器组成的初始类加载器层次结构:        bootstrap classloader                 |        exte ...

  8. AnyCAD脚本模型

    采用AnyCAD建立的模型, 基于AnyCAD.Net SDK在C#中展示模型:

  9. IOS数据解析JSON

    //非原创 作为一种轻量级的数据交换格式,json正在逐步取代xml,成为网络数据的通用格式. 有的json代码格式比较混乱,可以使用此“http://www.bejson.com/”网站来进行JSO ...

  10. PCB参数计算神器-Saturn PCB Design Toolkit下载及安装指南

    进行PCB设计,特别是高频高速设计时,难免会涉及到PCB相关参数的计算及设置,如:VIA的过流能力,VIA的寄生电容.阻抗等,导线的载流能力,两相互耦合信号线间的串扰,波长等参数. 这里向大家介绍一款 ...