poj3614Sunscreen
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 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 现附上AC代码:
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int cmp(pair<int ,int > a,pair<int ,int >b){
if(a.first==b.first) return a.second<b.second;
else return a.first<b.first;
}
int main(){
int C,L;
cin>>C>>L;
pair<int ,int > c[2510],va[2510];
for(int i=0;i<C;i++)
scanf("%d%d",&c[i].first,&c[i].second);
for(int j=0;j<L;j++)
scanf("%d%d",&va[j].first,&va[j].second);
priority_queue<int ,vector<int >,greater<int > >q;
sort(c,c+C,cmp);
sort(va,va+L,cmp);
int k=0,sum=0;
for(int i=0; i<L; i++){
while(k < C && c[k].first <= va[i].first){
q.push(c[k].second); k++;
}
while( !q.empty() && va[i].second)
{
int m = q.top();
q.pop();
if(m >= va[i].first) sum++,va[i].second--;
}
}
printf("%d",sum);
return 0;
}
思路:将两个数组的数据从小到大进行排序,
从最小的防晒霜枚举,将所有符合 防晒度的最小值小于等于该防晒霜的奶牛 最大值放入优先队列之中。然后优先队列是小值先出所以就可以将这些最大值中的最小的取出来。更新答案。
整体思路:防晒霜(由小到大)肯定是最先供给给最大值最小的奶牛,防止以后其他防晒霜闲置;
poj3614Sunscreen的更多相关文章
- 【优先队列】POJ3614-Sunscreen
参考:❀ #include<iostream> #include<cstdio> #include<queue> #include<algorithm> ...
随机推荐
- [AHOI2013]作业 (莫队+分块)
[AHOI2013]作业 (莫队+分块) 题面 给定了一个长度为n的数列和若干个询问,每个询问是关于数列的区间[l,r],首先你要统计该区间内大于等于a,小于等于b的数的个数,其次是所有大于等于a,小 ...
- SCUT - 274 - CC B-Tree - 树形dp
https://scut.online/p/274 首先要判断是一颗树,并且找出树的直径. 是一棵树,首先边恰好有n-1条,其次要连通,这两个条件已经充分了,当然判环可以加速. 两次dfs找出直径,一 ...
- vue css中scoped
1.什么是scoped vue组件中,在style标签中有一个属性,叫做scoped.当此标签拥有scoped属性的时候,该组件下的css样式只适用于本组件,而不会影响全局组件.这其实也相当于样式的模 ...
- jQuery——复选框操作
学习jQuer对表单.表格操作的过程中,按照书上的例子发现一个问题: <!DOCTYPE html> <html> <head> <title>复选框应 ...
- es6 promise 结束回调地狱
promise的三种状态: pending---进行中 fulfiled---执行成功 rejected---执行失败 var promise = new Promise(function(resol ...
- 超详细的DOM操作(增删改查)
操作DOM的核心就是增删改查 原文地址:https://jianshu.com/p/b0aa846f4dcc 目录 一.节点创建型API 1.1 createElement 1.2 createTex ...
- Linux性能优化从入门到实战:01 Linux性能优化学习路线
我通过阅读各种相关书籍,从操作系统原理.到 Linux内核,再到硬件驱动程序等等. 把观察到的性能问题跟系统原理关联起来,特别是把系统从应用程序.库函数.系统调用.再到内核和硬件等不同的层级贯 ...
- 第一次写的MySQLHelper
一. 第一次写MysqlHelper,用来管理城市的数据库 二.MySQLHelper源代码 using MySql.Data.MySqlClient; using System; using Sys ...
- python 日期封装
import time import datetime import locale class TimeUtil: def __init__(self, curtime=None): self.cur ...
- NLP第一周
19-21周,每周学习15小时以上 基础:Python编程基础:基础的概览统计.了解线性代数:足够的时间投入. 完成9个课程项目,每个5小时-15小时 完成聊天机器人项目(40-80小时) Capst ...