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]次,问最大匹配数.可以用图论做. 也可以贪心.贪心的思想是,把区间和点排序以后,考虑最左边的点,加入和这个点相交的区间, 并排除出界的区间 ...
随机推荐
- JavaScript 对象继承 OOP (三)
对象继承 A 对象通过继承 B 对象,就能直接拥有 B 对象的所有属性和方法.这对于代码的复用是非常有用的. JavaScript 语言的继承不通过 class (es6 中的class 不过是 ...
- 在CentOS上配置redis服务
#!/bin/sh # # redis Startup script for Redis Server # # chkconfig: - 80 12 # description: Redis is a ...
- 简单封装的web里面的tab点击和swipe滑动的小插件
简单封装的一个web的手势,tab和swipe,里面的具体数值都是自定义上去的,没有实际的标准,可以自行去修改都行 前两个是详解,js插件在最后一部分代码 ``` //封装web的tab步骤详解 &l ...
- Kindeditor单独调用单图上传增加预览
html代码: <p><input type="hidden" id="url1" name="IDCardPicture1&quo ...
- wxWidgets窗口类型
如果在创建窗口的时候你没有指定窗口的边框类型,那么在不同的平台上将会有不同的边框类型的缺省值.在windows平台上,控件边框的缺省值为 wxSUNKEN_BORDER,意为使用当前系统风格的边框.你 ...
- Python OOP 面向对象
1.Python实现OOP可以概括为三个概念: 继承:基于Python属性查找 多态:在x.method中,method的意义取决于x的类型 封装:方法和运算符实现行为,数据隐藏是一种惯例 2.委托: ...
- DEM精度评价自动化系统的成果展示
程序员:左正康 完成时间:2013/12/3 系统开发背景: 原始的DEM精度评价方法:采用ArcGIS结合Excel的方式完成DEM的精度评价.具体操作是:利用ArcGIS工具箱中的创建TIN,T ...
- Linux下内存的几个基本概念
先介绍几个基本概念: SIZE: 进程使用的地址空间, 如果进程映射了100M的内存, 进程的地址空间将报告为100M内存. 事实上, 这个大小不是一个程序实际使用的内存数. RSS: "R ...
- hadoop中compare函数
在看hadoop 的二次排序的时候,改写了下, 加了第三个参数, 本来以为是在 public int compareTo(IntPair o) { System.out.println(" ...
- IIS 处理程序“PageHandlerFactory-Integrated”
出现这种错误是因为先安装了.net framework 4.0然后才安装了iis,此种情况下iis默认只支持.net framewrok 2.0,要解决此问题,需要在iis中注册.net framew ...