传送门:http://poj.org/problem?id=3614

Sunscreen

Time Limit: 1000MS Memory Limit: 65536K

Total Submissions: 10136 Accepted: 3544

Description

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?

Input

  • Line 1: Two space-separated integers: C and L
  • Lines 2..C+1: Line i describes cow i’s lotion require

s 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

Output

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


解题心得:

  1. 题意就是奶牛要去日光浴,奶牛要涂防晒霜,每个奶牛有一个涂防晒霜的区间,每个防晒霜有一个值和数量,问最多可以涂多少只奶牛。
  2. 其实面对的最大的问题就是一个奶牛将可以用多个防晒霜,但是它用了其中一个和另一个奶牛产生冲突的防晒霜,所以可以将防晒霜按照值排序,每次取一个出来,将最小值小于这个防晒霜的奶牛都压入优先队列(按照终点排序),再从优先队列中来取。这样就能先安排好奶终点先结束的奶牛。

#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std; const int maxn = 2510;
typedef pair <int,int> P; P cow[maxn],co[maxn];
int n,m; int main() {
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d%d",&cow[i].first,&cow[i].second);
for(int i=0;i<m;i++)
scanf("%d%d",&co[i].first,&co[i].second); sort(cow,cow+n);
sort(co,co+m); priority_queue <int, vector<int> , greater <int> > qu;
int j = 0,ans = 0;
for(int i=0;i<m;i++) {
while(j<n && cow[j].first <= co[i].first) {
qu.push(cow[j].second);
j++;
} while(!qu.empty() && co[i].second) {
if(qu.top() >= co[i].first) {
ans++;
co[i].second--;
}
qu.pop();
}
} printf("%d\n",ans);
return 0;
}

POJ :3614-Sunscreen的更多相关文章

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

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

  2. POJ 3614 Sunscreen 贪心

    题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...

  3. poj:4091:The Closest M Points

    poj:4091:The Closest M Points 题目 描写叙述 每到饭点,就又到了一日几度的小L纠结去哪吃饭的时候了.由于有太多太多好吃的地方能够去吃,而小L又比較懒不想走太远,所以小L会 ...

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

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

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

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

  6. poj 3614 Sunscreen

                                                                                                        ...

  7. POJ 3614 Sunscreen (优先队列)

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

  8. POJ 3614 Sunscreen 优先队列 贪心

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

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

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

随机推荐

  1. 用代码初始化AE控件许可

    当AE二次开发与其他平台一起使用的时候,有时候会不方便加LicenseControl控件,需要用代码初始化许可: 在构造函数中初始化许可: public Form1() { InitializeCom ...

  2. java中将数组、对象、Map、List转换成JSON数据

    如果要将数组.对象.Map.List转换成JSON数据,那我们需要一些jar包: json-lib-2.4-jdk15.jar ezmorph-1.0.6.jar commons-logging.ja ...

  3. PHP使用MySQL报no such file or directory

    原因是没有连接数据库.加上下面代码: $link = mysql_connect(DB_HOST,DB_USER,DB_PWD);mysql_select_db(DB_NAME) or die('Co ...

  4. 笨办法学Python(三十七)

    习题 37: 复习各种符号 现在该复习你学过的符号和 python 关键字了,而且你在本节还会学到一些新的东西.我在这里所作的是将所有的 Python 符号和关键字列出来,这些都是值得掌握的重点. 在 ...

  5. 修改hosts工具推荐SwitchHosts

    推荐一个修改hosts的工具.适合平时工作中经常修改hosts的开发测试. 下载地址:https://oldj.github.io/SwitchHosts/ 可以按各种环境或者项目添加,用的时候打开或 ...

  6. EF写in

    qualityStatisticsInfoSql.Where(t => successStateArray.Contains(t.UploadReportFlag)); 如果写成 quality ...

  7. Poj(1521),哈夫曼编码

    题目链接:http://poj.org/problem?id=1521 这里,网上有很多博客都有写,很多人没有建树,直接就是求一下这个哈夫曼编码的长度,的确很巧妙,我也用的这个方法,但是,几乎所有博客 ...

  8. P1823 Patrik 音乐会的等待

    题目描述 N个人正在排队进入一个音乐会.人们等得很无聊,于是他们开始转来转去,想在队伍里寻找自己的熟进行谈笑风生.队列中任意两个人A和B,如果他们是相邻或他们之间没有人比A或B高,那么他们是可以互相看 ...

  9. 批量删除xml文件中的<?xml version="1.0" ?>

    #!/bin/shcd 'home/usrname/'ls cd '/home/usrname/VOC2007/Annotations/' for file in `ls /home/usrname/ ...

  10. Excle 常用函数

    1. 查找函数VLOOKUP 使用示例: =VLOOKUP(A1,$C$1:$D$19,2,0) 表示以A1单元格为基准,匹配C1开始到D19的范围数据,在公式行显示D单元格文本,也就是匹配范围的第二 ...