• POJ 3614 Sunscreen (优先队列)


    题意:奶牛美容:有C头奶牛日光浴,每头奶牛分别需要minSPF_i和maxSPF_i单位强度之间的阳光。现有L种防晒霜,分别能使阳光强度稳定为SPF_i,其瓶数为cover_i。求最多满足多少头奶牛

    思路:

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

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

    然后优先队列是小值先出,所以就可以将这些最大值中的最小的取出来。更新答案。

    #include <iostream>  
    #include <algorithm>  
    #include <cstring>  
    #include <cstdio>  
    #include <map>  
    #include <vector>  
    #include <queue>  
    #define MAXN 2555   
    using namespace std;
    int C, L;
    typedef pair<int, int> P;
    priority_queue<int, vector<int>, greater<int> > q;
    P cow[MAXN], bot[MAXN];
    int main()
    {
    	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", &bot[i].first, &bot[i].second);
    	sort(cow, cow + C);
    	sort(bot, bot + L);
    	int j = 0, ans = 0;
    	for (int i = 0; i < L; i++)
    	{
    		while (j < C && cow[j].first <= bot[i].first)
    		{
    			q.push(cow[j].second);
    			j++;
    		}
    		while (!q.empty() && bot[i].second)
    		{
    			int x = q.top();
    			q.pop();
    			if (x < bot[i].first) continue;
    			ans++;
    			bot[i].second--;
    		}
    	}
    	printf("%d
    ", ans);
    	return 0;
    }
  • 相关阅读:
    Ansys Maxwell2——二维电磁场理论和有限元基础
    Ansys Maxwell在工程电磁场中的应用1——二维分析技术
    第四章 栈
    第三章 链表
    第二章 队列
    第三章 操作系统用户界面总结
    第一章 逻辑结构与物理结构
    Linux-Mint的一些配置经验
    docker安装zookeeper的使用说明
    SpringCloud初体验-使用Eureka进行服务注册和发现
  • 原文地址:https://www.cnblogs.com/demian/p/7373530.html
Copyright © 2020-2023  润新知