晒太阳

  题目大意:一堆牛,为了避免晒太阳会灼烧自己,然后他们自己有自己的防晒指数(一个区间),防晒霜可以提高防晒因数SPF,大了不行小了不行,现在有一桶防晒霜,他们提供一定的SPF,但是最多可以提供k头牛使用,问你这堆防晒霜最多可以给多少头牛提供保护?

  大水题,我们用贪心就可以了,把防晒因数尽量给SPF_MIN大的用(还要比较SPF_MAX满足要求与否),就是建堆,然后不断贪心就可以了。

  

 #include <iostream>
#include <functional>
#include <algorithm>
#include <queue> using namespace std; typedef struct cow_set_
{
int min_SPF;
int max_SPF;
}COWS;
typedef struct lotion_set_
{
int SPF;
int cover;
bool operator < (const lotion_set_ &x) const //自定义比较函数
{
return SPF < x.SPF;//最大值优先
}
}Lotion; int fcomp(const void *a, const void *b)
{
if ((*(COWS *)a).min_SPF == (*(COWS *)b).min_SPF)
{
return (*(COWS *)b).max_SPF - (*(COWS *)a).max_SPF;
}
else
return (*(COWS *)b).min_SPF - (*(COWS *)a).min_SPF;//由大到小排列
} static COWS cows_set[];
static bool used[];
priority_queue<lotion_set_>que_lotion; void Search(const int); int main(void)
{
int cow_sum, lotion_sum;
Lotion tmp; while (~scanf("%d%d", &cow_sum, &lotion_sum))
{
for (int i = ; i < cow_sum; i++)
scanf("%d%d", &cows_set[i].min_SPF, &cows_set[i].max_SPF);
for (int i = ; i < lotion_sum; i++)
{
scanf("%d%d", &tmp.SPF, &tmp.cover);
que_lotion.push(tmp);
}
qsort(cows_set, cow_sum, sizeof(COWS), fcomp);
Search(cow_sum);
}
return ;
} void Search(const int cow_sum)
{
int ans = , tmp_cover;
Lotion out;
memset(used, , sizeof(used)); while (!que_lotion.empty())
{
out = que_lotion.top(); que_lotion.pop();
tmp_cover = out.cover;
for (int j = ; j < cow_sum && tmp_cover != ; j++)
{
if (used[j]) continue;
if (cows_set[j].max_SPF < out.SPF
|| cows_set[j].min_SPF > out.SPF)
continue; used[j] = ; ans++; tmp_cover--;
}
}
printf("%d\n", ans);
}

还有这一次用了STL的堆,不知道为什么STL的堆总是比我自己手动写的要慢一点,可能是因为STL要先要一片区域的原因

Heap:Sunscreen(POJ 3614)的更多相关文章

  1. Sunscreen POJ - 3614(贪心)

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

  2. POJ 3614 Sunscreen 贪心

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

  3. 【POJ 3614 Sunscreen】贪心 优先级队列

    题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...

  4. poj -3614 Sunscreen(贪心 + 优先队列)

    http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...

  5. 【POJ 3614】 Sunscreen

    [题目链接] http://poj.org/problem?id=3614 [算法] 将MinSPF从大到小排序,每头牛找SPF值最大的防晒霜 [代码] #include <algorithm& ...

  6. poj 3614 Sunscreen

                                                                                                        ...

  7. Sunscreen(POJ 3614 优先队列)

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

  8. POJ 3614 Sunscreen(贪心,区间单点匹配)

    把牛的SPF看作一个区间,防晒霜看作点.一个点可以匹配C[i]次,问最大匹配数.可以用图论做. 也可以贪心.贪心的思想是,把区间和点排序以后,考虑最左边的点,加入和这个点相交的区间, 并排除出界的区间 ...

  9. 【POJ - 3614】Sunscreen (优先队列)

    Sunscreen Descriptions C (1 ≤ C ≤ 2500) 头奶牛在海滩边晒太阳,要避免在日光浴时产生难看的灼伤,每头奶牛必须用防晒霜覆盖它的皮肤.第 i 头奶牛有一个最小和最大  ...

随机推荐

  1. 【HDU 1445】Ride to School

    题 题意 骑自行车,等0时开始最早出发的人,一起出发,然后被别人超过时,就追上去,终点距离是4.5km,速度单位是km/s,求到达的时间(s). 分析 贪心,找0时开始最早到的即可. 代码 #incl ...

  2. Spring+C3P0数据库连接池配置

    一.xml文件读取.properties文件连接数据库 1.xml文件中的配置 <bean id="dataSourceLocal" name="dataSourc ...

  3. .net 时间戳互相转换(精确到毫秒)

    这里记录一个时间戳的互相转换方法,网上都找了,基本都没有精确到毫秒,我的这个基本可以满足精确到毫秒的级别,代码如下: /// <summary> /// Unix时间戳转换为DateTim ...

  4. POJ3714 Raid

    Raid Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 10625   Accepted: 3192 Description ...

  5. 获取本机IP_考虑多网卡的情况

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  6. 排序算法二(时间复杂度为O(N*logN))

    快速排序: 1 package test; public class QuickSort { // 快速排序 public void quickSort(int s[], int l, int r) ...

  7. 轻量级应用开发之(10) UINavigationController导航控制器

    一 多控制器 1)一个iOS的app很少只由一个控制器组成,除非这个app极其简单2)当app中有多个控制器的时候,我们就需要对这些控制器进行管理3)有多个view时,可以用一个大的view去管理1个 ...

  8. 对A*算法的改进

    对sunway程序中的BUG所进行的修改 需要注意的是Sunway上面文章“深入A*算法”中引用了一个A*的游戏程序进行讲解,并有这个源码的下载,不过它有一个不小的Bug, 就是新的子节点放入OPEN ...

  9. Conjugate prior relationships

    Conjugate prior relationships The following diagram summarizes conjugate prior relationships for a n ...

  10. JS 下拉菜单

    HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...