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]次,问最大匹配数.可以用图论做. 也可以贪心.贪心的思想是,把区间和点排序以后,考虑最左边的点,加入和这个点相交的区间, 并排除出界的区间 ...
随机推荐
- 【Android 界面效果48】Android-RecyclerView-Item点击事件设置
在上一篇博客Android-RecylerView初识中提到,RecyclerView不再负责Item视图的布局及显示,所以RecyclerView也没有为Item开放OnItemClick等点击事件 ...
- 青石B2C商城
平台: Windows 类型: 虚拟机镜像 软件包: azure commercial ecbluestone ecommerce ecommerce solution 服务优惠价: 按服务商许可协议 ...
- 翻译-ExcelDNA开发文档
转载自个人主页 前言 翻译开源项目ExcelDNA开发文档 异步处理 ExcelDNA支持两种异步函数: RTD,该函数适用与Excel2003及以上版本,(当你使用ExcelAsyncUtil.*时 ...
- Scala OOP
Scala OOP 1.介绍 Scala是对java的封装,底层仍然采用java来实现,因此Scala也是面向对象的.其中scala给出了class.object和trait三种面向对象的组件.
- 谁动了我的I/O?
首先,是信用卡账单欠款0.13美刀~~~然后上亚马逊云查了一下账单. 3M次I/O...(1215133次超额的,2000000次免费的.) 于是监控了一下数据:每秒至少写5次,每秒写300KB,平均 ...
- winform datagridview 如何设置datagridview隔行变色
如何设置隔行变色. 如图:
- Python-Django框架学习笔记——第一课:Hello World
Python Django 有诗云: 孤山寺北贾亭西,水面初平云脚低. 几处早莺争暖树,谁家新燕啄春泥. 乱花渐欲迷人眼,浅草才能没马蹄. 最爱湖东行不足,绿杨阴里白沙堤. 今天在信阳游玩,有幸来到信 ...
- Dijkstra单源最短路径,POJ(2387)
题目链接:http://poj.org/problem?id=2387 Dijkstra算法: //求某一点(源点)到另一点的最短路,算法其实也和源点到所有点的时间复杂度一样,O(n^2); 图G(V ...
- python 爬取猫眼榜单100(二)--多个页面以及多进程
#!/usr/bin/env python # -*- coding: utf- -*- # @Author: Dang Kai # @Date: -- :: # @Last Modified tim ...
- GNOME keyring [(null)] 的密码:
在ubuntu下执行svn checkout命令时,总是报下面的错误: GNOME keyring [(null)] 的密码:svn: 方法 OPTIONS 失败于 “http://xxxxxxxx/ ...