POJ3614 Sunscreen【贪心】
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10348 | Accepted: 3618 |
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 SPFrating (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 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
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
Source
问题链接:POJ3614 Sunscreen
问题简述:
有C(1<=C<=2500)头奶牛晒太阳 ,每个奶牛有各自能够忍受阳光强度的最小值和最大值。奶牛需要涂抹防晒霜,防太阳光照射。阳光太大晒伤了,太小奶牛没感觉。
给出了L(1<=L<=2500)种防晒霜,并且给出能抵御的阳光强度和数量(能涂抹几头牛)。
求有几头奶牛能够享受晒太阳。
问题分析:
典型的贪心问题。
奶牛按照能够忍受阳光强度的最小值从小到大排序。防晒霜也按照能够抵御的阳光强度从小到大排序。然后,进行匹配,防晒霜按照能够抵御的阳光强度从小到大进行处理,符合奶牛的最小值小于或等于防晒霜的,将奶牛的最大值放入优先队列之中。然后优先队列按最大值的从小到大顺序出队。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:
/* POJ3614 Sunscreen */#include <iostream>
#include <algorithm>
#include <queue>
#include <stdio.h>using namespace std;typedef pair<int, int> PAIR;
const int N = 2500;
PAIR cow[N], bottle[N];int main()
{int c, l;priority_queue<int, vector<int>, greater<int> > q;scanf("%d%d", &c, &l);for(int i = 0; i < c; i++)scanf("%d%d", &cow[i].first, &cow[i].second);for(int i = 0; i < l; i++)scanf("%d%d", &bottle[i].first, &bottle[i].second);sort(cow, cow + c);sort(bottle, bottle + l);int ans = 0, k = 0;for(int i = 0; i < l; i++) {while(k < c && cow[k].first <= bottle[i].first)q.push(cow[k++].second);while(!q.empty() && bottle[i].second) {int a = q.top();q.pop();if(a < bottle[i].first)continue;ans++;bottle[i].second--;}}printf("%d\n", ans);return 0;
}
POJ3614 Sunscreen【贪心】相关推荐
- POJ - 3614 Sunscreen(贪心/二分图最大匹配-多重匹配/网络流-最大流)
题目链接:点击查看 题目大意:给出n头奶牛,奶牛们现在要晒太阳,每头奶牛需要[l,r]区间内的光照强度,现在有m种防晒霜,每种防晒霜可以让奶牛接受到val数值的光照强度,然后每种防晒霜只有num个,现 ...
- P2887 [USACO07NOV]防晒霜Sunscreen - 贪心
貌似这种区间贪心题多数是排序加堆来做... 使尽量多的奶牛被抹,需要用最贴近他下限的防晒霜去抹,考虑完他的下限是否可行之后,还要考虑那些要使用相同防晒霜的奶牛,应该优先分配给上限最低的 奶牛按下限,防 ...
- ICPC程序设计题解书籍系列之三:秋田拓哉:《挑战程序设计竞赛》(第2版)
白书<挑战程序设计竞赛>(第2版)题目一览 白书:秋田拓哉:<挑战程序设计竞赛>(第2版) 第1章 蓄势待发--准备篇(例题) POJ1852 UVa10714 ZOJ2376 ...
- 算法竞赛进阶指南第一章--题解
例题:CH0103 最短Hamilton路径 题意: 给定一张n(<20)个点的带权无向图,点从0~n-1编号,求起点0到终点n-1的最短hanmilton路径: h路径的定义为0~n-1不重不 ...
- 《算法竞赛进阶指南》刷题记录
总算闲下来一些辣!然后最近发现其实看书是真真很有效但是一直没有落实!所以决定落实一下这段时间把这本书看完题目做完! 然后发现还有挺多题目挺巧妙的于是一堆博客预警,,,可能最近会写很多比较水(但是我还是 ...
- USACO 2007 NOV Sunscreen 防晒霜 贪心
题目 题目描述 To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hid ...
- POJ3614 [USACO07NOV]防晒霜Sunscreen
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9333 Accepted: 3264 Descrip ...
- 【贪心】防晒霜Sunscreen
防晒霜Sunscreen 题目 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的 ...
- POJ3614奶牛晒阳光DINIC或者贪心
题意: n个区间,m种点,每种点有ci个,如果一个点的范围在一个区间上,那么就可以消耗掉一个区间,问最多可以消耗多少个区间,就是这n个区间中,有多少个可能被抵消掉. 思路: 方 ...
最新文章
- 基本类型变量和引用型类型变量
- JavaWeb开发模式:C/S模式,B/S模式,JSP+JavaBean模式,JSP+Servlet+JavaBean模式
- Oracle 根据一张发票的供应商,取供应商所有符合条件的发票的总额
- 今天的一切准备就绪的局域网聊天
- 《4月份数据库技术通讯》.pdf
- ES6新特性_Promise介绍与基本使用---JavaScript_ECMAScript_ES6-ES11新特性工作笔记024
- python基础知识 01
- Eventbus收录
- ie8 html5上传,兼容IE8的file单文件上传(jquery.form+formdata)
- C语言判断素数(求素数)
- Xamarin入门一 环境准备
- python 密度聚类_Python密度聚类算法-DBSCAN实践
- 收藏!豆瓣9.0分TOP100职场终极必读书单!大萌哥整理
- 上帝视角!美国记者用公开数据,还原川普的全天行动轨迹
- 痞子衡嵌入式:我被邀请做贸泽电子与非网联合推出的《对话工程师》节目嘉宾...
- 使用python画出彩虹效果
- Android 仿钉钉、微信 群聊组合头像
- 算法之BTree(Java版)
- mysql 慢日志可视化_Mysql 慢日志分析系统搭建 —— Box Anemometer
- Centos 查看/搜素日志 查找文件、目录、内容等 常用命令
热门文章
- oracle——监听(一、多实例监听配置)
- Intellij IDEA 添加jar包的三种方式
- Intellij Idea打包jar
- linux haokande shell,5 个 PowerShell 主题,让你的 Windows 终端更好看
- pandas将某列复制到另一个表_使用pandas将列从一个数据帧复制到另一个数据帧的最快方法?...
- hadoop中的合并(Combine)与归并(Merge)
- Scala学习之Option类
- linux文件共享加锁,Linux共享数据管理——文件锁定
- 圣诞节就这么过了.........
- MPAA正在对BT下毒手,BT大站被警方关闭