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; minSPFimaxSPFi ≤ 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

题意

有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉。

而刚开始的阳光的强度非常大,奶牛都承受不住,然后奶牛就得涂抹防晒霜,防晒霜的作用是让阳光照在身上的阳光强度固定为某个值。

那么为了不让奶牛烫伤,又不会没有效果。

给出了L种防晒霜。每种的数量和固定的阳光强度也给出来了

每个奶牛只能抹一瓶防晒霜,最后问能够享受晒太阳的奶牛有几个。

可以将奶牛按照阳光强度的最小值从小到大排序。

将防晒霜也按照能固定的阳光强度从小到大排序

从最小的防晒霜枚举,将所有符合  最小值小于等于该防晒霜的 奶牛的 最大值 放入优先队列之中。

然后优先队列是小值先出

所以就可以将这些最大值中的最小的取出来。更新答案。

#include <iostream>
#include <algorithm>
#include <queue> using namespace std;
typedef pair<int,int> p;
priority_queue <int, vector<int>, greater<int> > q;
//定义优先队列,小的先出队
p n[2505], b[2505]; bool cmp(p x, p y)//按pair类的第一个值排序
{
return x.first<y.first;
} int main()
{
int C, L, sum;
cin >> C >> L ;
for(int i=0; i<C; i++)
cin >> n[i].first >> n[i].second ;
for(int i=0; i<L; i++)
cin >> b[i].first >> b[i].second ;
sort(n,n+C,cmp);
sort(b,b+L,cmp);
int j = 0 ;
sum = 0 ;
for(int i=0; i<L; i++)
{
while( j<C && n[j].first<=b[i].first)
{
q.push(n[j].second);
j++ ;
}
while(!q.empty() && b[i].second)
{
int temp = q.top() ;
q.pop();
if(temp < b[i].first) continue ;
sum ++ ;
b[i].second -- ;
}
}
cout << sum << endl ; return 0;
}

ACM题目————Sunscreen的更多相关文章

  1. ACM题目————中缀表达式转后缀

    题目描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说)操作符在两个操作数中间:num1 operand num2.同理,后缀表达式就是操作符在两 ...

  2. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  3. ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]

    原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...

  4. 有一种acm题目叫做,奇葩!

    本文全然没有技术含量,纯粹是娱乐. 我事实上想写点东西.可是近期好像做计算几何做得太多了,一种想说说不出东西的感觉,唯有写一下一些奇葩的题目了. HDU3337:Guess the number pi ...

  5. ACM题目————STL练习之求次数

    题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...

  6. ACM题目————zoj问题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:20322 解决:3560 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. ...

  7. ACM题目————又见拦截导弹

    描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:它的第一发炮弹能够到达任意的高度,但是以后每一发炮 ...

  8. ACM题目————还是畅通工程

    Submit Status Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路 ...

  9. ACM题目————小A的计算器

    Description 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-25分别由a-z表示.  现在小A要在这个操作系统上实现一个计算器,这 ...

随机推荐

  1. Nginx 日志 worker_connections are not enough while connecting to upstream

    记一次,排查错误所遇到的问题,和学习到的内容. 上周五,刚上线的项目出现了503 ,查看日志发现如下内容: System.Exception: Request api/blogpost/zzkDocs ...

  2. hihocoder 1305 - 区间求差 - [hiho一下152周][区间问题]

    题目链接:https://hihocoder.com/problemset/problem/1305 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个区间集合 A ...

  3. 疯狂java讲义 第三版 笔记

      java7新加特性: 0B010101  二进制数 int c=0B0111_1111;   数值中使用下划线分隔 switch 支持String类型   字符串常量放在常量池 String s0 ...

  4. svm核函数的理解和选择

    https://blog.csdn.net/leonis_v/article/details/50688766 特征空间的隐式映射:核函数    咱们首先给出核函数的来头:在上文中,我们已经了解到了S ...

  5. 2018/04/07 每日一个Linux命令 之 logrotate

    简介 日志的存在一直是 Linux 里面一个比较重要内容. 但是随着服务器运行的时间越来越长,日志越来越大.我见过一个线上项目 TP3.2 log文件有260+G的...... logrotate 也 ...

  6. es fielddata理解

    在es中,text类型的字段使用一种叫做fielddata的查询时内存数据结构.当字段被排序,聚合或者通过脚本访问时这种数据结构会被创建.它是通过从磁盘读取每个段的整个反向索引来构建的,然后存存储在j ...

  7. Subsequence---poj3061(尺取法||二分)

    题目链接:http://poj.org/problem?id=3061 题意:给n个正整数和一个数S,求出总和不小于S的连续子序列的长度的最小值,如果无解输出0: 我们可以用sum[i]表示前i项的和 ...

  8. Find The Multiple--POJ1426

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...

  9. 洛谷P3244 落忆枫音 [HNOI2015] 拓扑排序+dp

    正解:拓扑排序+dp 解题报告: 传送门 我好暴躁昂,,,怎么感觉HNOI每年总有那么几道题题面巨长啊,,,语文不好真是太心痛辣QAQ 所以还是要简述一下题意,,,就是说,本来是有一个DAG,然后后来 ...

  10. java执行Shell命令

    java程序中要执行linux命令主要依赖2个类:Process和Runtime首先看一下Process类:ProcessBuilder.start() 和 Runtime.exec 方法创建一个本机 ...