Heap:Sunscreen(POJ 3614)

题目大意:一堆牛,为了避免晒太阳会灼烧自己,然后他们自己有自己的防晒指数(一个区间),防晒霜可以提高防晒因数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)的更多相关文章
- Sunscreen POJ - 3614(贪心)
To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide with s ...
- POJ 3614 Sunscreen 贪心
题目链接: http://poj.org/problem?id=3614 Sunscreen Time Limit: 1000MSMemory Limit: 65536K 问题描述 to avoid ...
- 【POJ 3614 Sunscreen】贪心 优先级队列
题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...
- poj -3614 Sunscreen(贪心 + 优先队列)
http://poj.org/problem?id=3614 有c头奶牛在沙滩上晒太阳,每头奶牛能忍受的阳光强度有一个最大值(max_spf) 和最小值(min_spf),奶牛有L种防晒霜,每种可以固 ...
- 【POJ 3614】 Sunscreen
[题目链接] http://poj.org/problem?id=3614 [算法] 将MinSPF从大到小排序,每头牛找SPF值最大的防晒霜 [代码] #include <algorithm& ...
- poj 3614 Sunscreen
...
- Sunscreen(POJ 3614 优先队列)
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5898 Accepted: 2068 Descrip ...
- POJ 3614 Sunscreen(贪心,区间单点匹配)
把牛的SPF看作一个区间,防晒霜看作点.一个点可以匹配C[i]次,问最大匹配数.可以用图论做. 也可以贪心.贪心的思想是,把区间和点排序以后,考虑最左边的点,加入和这个点相交的区间, 并排除出界的区间 ...
- 【POJ - 3614】Sunscreen (优先队列)
Sunscreen Descriptions C (1 ≤ C ≤ 2500) 头奶牛在海滩边晒太阳,要避免在日光浴时产生难看的灼伤,每头奶牛必须用防晒霜覆盖它的皮肤.第 i 头奶牛有一个最小和最大 ...
随机推荐
- NOIP 2014 Day1 T3飞扬的小鸟
题目描述:http://codevs.cn/problem/3729/ 表示各种shabi的我编和调了半天,思路大体就是一个完全背包的模型,不过会多一些额外的转移(因为题目限制高度之类的),不过值得注 ...
- 抓包利器Fiddler
1).Fiddler安装 a.下载地址: http://fiddler2.com/get-fiddler b.安装:省略(下一步...下一步即可) 2).Fiddler配置 a.允许远程计算机连接Fi ...
- Codeforces 650A Watchmen
传送门 time limit per test 3 seconds memory limit per test 256 megabytes input standard input output st ...
- TP中二维数组的遍历输出
例子分析 <volist name="list" id="vo"> <volist name="vo['sub']" id ...
- SpringMVC 和Struts2的区别
SpringMVC 和Struts2的区别 1. 机制: spring mvc的入口是servlet,而struts2是filter,这样就导致了二者的机制不同. 2. 性能: spring会稍微比s ...
- linux find 命令详解
Linux下 利用find命令删除所有vssver2.scc文件 删除所有vssver2.scc文件 这是我当初查找 Linux find 命令的目的所在 1) find / -name ‘vssv ...
- curl模拟post请求
1,curl -d "userType=seller&userId=1034285" "www.baidu.com/getInfo.php" curl ...
- 如何卸载lnmp
转自:https://www.centos.bz/2011/07/howto-remove-lnmp/ killall nginx /etc/init.d/mysql stop killall mys ...
- C# JavascriptSerializer与匿名对象打造Json的完美工具
一:背景 在web项目中经常需要生成json数据,返回给前端ajax. 无论是ashx,还是WebMethod,可以人工的用字符串去拼接,最终得到json数据. 有没有更好的方法呢?我个人推荐使用Ja ...
- JavaScript中,window.opener是什么?window.parent和window.opener有啥区别?
来自CSDN的问答: window.opener是什么啊? ++++++++++++++++++++++++++++++++++++++++++++++++++ 弹出本窗体的句柄 比如你想点一个按钮直 ...