POJ :3614-Sunscreen
传送门: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
解题心得:
- 题意就是奶牛要去日光浴,奶牛要涂防晒霜,每个奶牛有一个涂防晒霜的区间,每个防晒霜有一个值和数量,问最多可以涂多少只奶牛。
- 其实面对的最大的问题就是一个奶牛将可以用多个防晒霜,但是它用了其中一个和另一个奶牛产生冲突的防晒霜,所以可以将防晒霜按照值排序,每次取一个出来,将最小值小于这个防晒霜的奶牛都压入优先队列(按照终点排序),再从优先队列中来取。这样就能先安排好奶终点先结束的奶牛。
#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的更多相关文章
- 优先队列:POJ No 3614 Sunscreen 贪心
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6410 Accepted: 2239 Descrip ...
- POJ 3614 Sunscreen 贪心
题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...
- poj:4091:The Closest M Points
poj:4091:The Closest M Points 题目 描写叙述 每到饭点,就又到了一日几度的小L纠结去哪吃饭的时候了.由于有太多太多好吃的地方能够去吃,而小L又比較懒不想走太远,所以小L会 ...
- 【POJ 3614 Sunscreen】贪心 优先级队列
题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...
- poj -3614 Sunscreen(贪心 + 优先队列)
http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...
- poj 3614 Sunscreen
...
- POJ 3614 Sunscreen (优先队列)
题意:奶牛美容:有C头奶牛日光浴,每头奶牛分别需要minSPF_i和maxSPF_i单位强度之间的阳光.现有L种防晒霜,分别能使阳光强度稳定为SPF_i,其瓶数为cover_i.求最多满足多少头奶牛 ...
- POJ 3614 Sunscreen 优先队列 贪心
题意 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常大,奶牛都承受不住 ...
- POJ 3614 Sunscreen(贪心,区间单点匹配)
把牛的SPF看作一个区间,防晒霜看作点.一个点可以匹配C[i]次,问最大匹配数.可以用图论做. 也可以贪心.贪心的思想是,把区间和点排序以后,考虑最左边的点,加入和这个点相交的区间, 并排除出界的区间 ...
随机推荐
- u-boot分析(十)----堆栈设置|代码拷贝|完成BL1阶段
u-boot分析(十) 上篇博文我们按照210的启动流程,分析到了初始化nand flash,由于接下来的关闭ABB比较简单所以跳过,所以我们今天按照u-boot的启动流程继续进行分析. 今天我们会用 ...
- Struts2_HelloWorld1
打开 eclipse,新建 web 项目. 因为可能需要 jstl 表达式,所以添加 jstl需要的jar包. 下载链接:http://pan.baidu.com/s/1hr6mBI0 将jar拷贝至 ...
- selenium grid 使用方法
代码和selenium driver相同 只是 启动环境方式不同.至少启动一个hub 一个 node .如需要多个,可以使用端口进行区分. java -jar selenium-server-stan ...
- 2017年10月31日结束Outlook 2007与Office 365的连接
2017 年10月31日 ,微软即将推出 Office 365中Exchange Online邮箱将需要Outlook for Windows的连接,即通过HTTP Over MAPI方式,传统使用R ...
- 数组:获取GET的键名
1.今天仓鼠遇到这个情况:通过$_GET获取参数,但是参数变成了键名形式 2.那仓鼠想要拿到这个键名,那就要:使用array_keys()获取数组中的所有键名,然后进行转换 代码如下: 结果: 以上 ...
- 如何启用SAP C4C OData Event Notification
当我们在试图使用SAP C4C OData事件通知这个功能时,如果遇到下列提示消息,说明这个功能在business configuration里没有开启: The OData Event Notifi ...
- QT学习之QT判断界面当前点击的按钮和当前鼠标坐标
1.QObject::sender( ) 返回发送信号的对象的指针,返回类型为QObject* .可使用qobject_cast动态类型转换成对应的发送信息的对象(对象类的基类中需要有QObject) ...
- C# 驱动的mongodb的分页查询简单示例
/// <summary> /// mongodb分页查询 /// </summary> /// <typeparam name="T">< ...
- 并查集,是否成树,Poj(1308)
思路: 对于每一条新的边的两个端点,是否是属于一颗树,要是的话,就不是一颗树.否则,就合并. 这里要注意的是,不能是森林,我这里WA了两次了.只不过在最后,查看每个节点的祖先是否是同一个就可以了. # ...
- LeetCode(Add Two Numbers)
一.题目要求 You are given two non-empty linked lists representing two non-negative integers. The digits a ...