传送门: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. Vue-Cli 3 引入 SCSS 全局变量

    首先创建一个全局变量文件 global.scss $theme-color: #efefef; 编辑vue.config.js module.exports = { // ... css: { loa ...

  2. 什么是MongoDb

    MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型.Mo ...

  3. css取消a标签在移动端点击时的背景颜色

    一.取消a标签在移动端点击时的蓝色 -webkit-tap-highlight-color: rgba(255, 255, 255, 0);-webkit-user-select: none;-moz ...

  4. CSS改变placeholder的颜色

    :-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #a1a1a1; } ::-moz-placeholder { /* Mozilla ...

  5. iOS - 通过view查找所在(viewController)

    - (UIViewController *)findViewController:(UIView *)sourceView { id target=sourceView; while (target) ...

  6. MySQL累加值时,考虑到值有为NULL的情况.

    一个字段,表示报名人数,默认为null,经考虑,以以下sql执行加1: ) where id='xxx'

  7. Android 切换主题换肤实现

    思路以及实现 1.主题的切换以及实现 首先我们先来明确个概念,现在我所说的切换主题,就切换整个app的颜色风格,当然也有少部分的图片的切换.注意哦 我这边说的是少部分图片哦!如果是大面积的换图片的吧! ...

  8. 心得整理之一--RDLC多数据源多表

    我将项目中的一部分提炼出来,写了这个Demo. 先说一下需求, 从 API接口, 获取数据源, 调用RDLC 生成PDF文件. (后面还有涉及到使用福昕PDf阅读器进行设置文件自定义内容,以供外部程序 ...

  9. IDEA导入Web项目

    最近尝试着从eclipse.myeclipse转到idea上面来开发. *注:以下仅适用于普通web项目.*  一.导入已有项目 File>Open...>选取自己的项目位置 二.添加ja ...

  10. C#保存图片到数据库并读取显示图片的方法

    private void button2_Click_1(object sender, System.EventArgs e) { string pathName; if (this.openFile ...