题目描述

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?

输入

* 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

输出

A single line with an integer that is the maximum number of cows that can be protected while tanning

样例输入

3 2
3 10
2 5
1 5
6 2
4 1

样例输出

2

分析:把奶牛按最小值排序,防晒霜按固定值排序,从最小的防晒霜枚举,满足条件即放入优先队列。再将最小值取出,更新ans。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int C,L;
pair<int,int> fuck[],you[];
priority_queue <int, vector<int>, greater<int> > q;
bool cmp(pair<int,int>a,pair<int,int>b){
return a.first<b.first;
}
void init() {
cin >> C >> L;
range(i, , C - )cin >> fuck[i].first >> fuck[i].second;
range(i, , L - )cin >> you[i].first >> you[i].second;
sort(fuck,fuck+C,cmp);
sort(you,you+L,cmp);
}
void solve(){
int j=,ans=;
range(i,,L-){
while(j<C&&fuck[j].first<=you[i].first){
q.push(fuck[j].second);
++j;
}
while(!q.empty()&&you[i].second){
int tmp=q.top();
q.pop();
if(tmp<you[i].first)continue;
++ans;
you[i].second--;
}
}
cout<<ans<<endl;
}
int main() {
init();
solve();
return ;
}

Sunscreen的更多相关文章

  1. POJ 3614 Sunscreen 贪心

    题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...

  2. poj 3614 Sunscreen

                                                                                                        ...

  3. Sunscreen(POJ 3614 优先队列)

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5898   Accepted: 2068 Descrip ...

  4. POJ3614 Sunscreen 优先队列+贪心

    Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...

  5. POJ--3614 Sunscreen(贪心)

    题目 3614 Sunscreen 2500*2500直接排序暴力贪心 #include<iostream> #include<cstring> #include<alg ...

  6. Sunscreen POJ - 3614(贪心)

    To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide with s ...

  7. 洛谷 P2887 [USACO07NOV]防晒霜Sunscreen 解题报告

    P2887 [USACO07NOV]防晒霜Sunscreen 题目描述 To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2 ...

  8. poj3614 Sunscreen【贪心】

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11772   Accepted: 4143 Descri ...

  9. ACM题目————Sunscreen

    Description To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her ...

  10. 优先队列:POJ No 3614 Sunscreen 贪心

    Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6410   Accepted: 2239 Descrip ...

随机推荐

  1. jmeter 运行脚本报错 java.net.BindException: Address already in use

    在win下跑jmeter时,在聚合报告中出现错误.打开日志文件(前提是将日志写入了指定文件) 发现报错的原因为:java.net.BindException: Address already in u ...

  2. jekens介绍及服务搭建

    https://blog.csdn.net/achuo/article/details/51086599 https://blog.csdn.net/qq_37372007/article/detai ...

  3. android配置开发环境

    1.下载Java SE并安装. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 配置环境变量 我的电脑- ...

  4. 201621123033 《Java程序设计》第9周学习总结

    第九次作业 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 //stream(),filter(),collect() ...

  5. 【bzoj4010】[HNOI2015]菜肴制作 拓扑排序+堆

    题目描述 给你一张有向图,问:编号-位置序(即每个编号的位置对应的序列)最小(例如1优先出现在前面,1位置相同的2优先出现在前面,以此类推)的拓扑序是什么? 输入 第一行是一个正整数D,表示数据组数. ...

  6. 【bzoj1044】[HAOI2008]木棍分割 二分+dp

    题目描述 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍被分成了很多段,要求满足总长度最大的一段长度最小, 并且 ...

  7. 【bzoj1927】[Sdoi2010]星际竞速 有上下界费用流

    原文地址:http://www.cnblogs.com/GXZlegend/p/6832464.html 题目描述 10年一度的银河系赛车大赛又要开始了.作为全银河最盛大的活动之一,夺得这个项目的冠军 ...

  8. [洛谷P3857][TJOI2008]彩灯

    题目大意:有$n$盏灯,$m$个开关($n,m\leqslant 50$),每个开关可以控制的灯用一串$OX$串表示,$O$表示可以控制(即按一下,灯的状态改变),$X$表示不可以控制,问有多少种灯的 ...

  9. BZOJ1025 [SCOI2009]游戏 【置换群 + 背包dp】

    题目链接 BZOJ1025 题解 题意就是问一个\(1....n\)的排列在同一个置换不断重复下回到\(1...n\)可能需要的次数的个数 和置换群也没太大关系 我们只需知道同一个置换不断重复,实际上 ...

  10. code forces 996D Suit and Tie

    D. Suit and Tie time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...