poj 3614 Sunscreen(优先队列+贪心)
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 Source
USACO 2007 November Gold
题意:
有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉。 而刚开始的阳光的强度非常大,奶牛都承受不住,然后奶牛就得涂抹防晒霜,防晒霜的作用是让阳光照在身上的阳光强度固定为某个值。 那么为了不让奶牛烫伤,又不会没有效果。 给出了L种防晒霜。每种的固定的阳光强度和数量也给出来了 每个奶牛只能抹一瓶防晒霜,最后问能够享受晒太阳的奶牛有几个。 思路:刚开始想错了,正确的方法为: 1、将牛按最小值从小到大排好序 2、将防嗮霜按阳光强度从小到大排好序 3、然后有一个优先队列,优先队列里按牛的最大值从小到大排序 4、遍历防晒霜,将牛的最小值<=防晒霜的值的牛push进优先队列,然后根据防晒霜的数量从队首开始选出符合的牛,这部分见代码 5、while(k<n && cow[k].l<=p[i].x)注意这里的判断条件要写在一起,刚开始分开写,将第二个条件写在下面的if中,结果TLE了。。。。。。 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 #include<algorithm> 6 #include<vector> 7 using namespace std; 8 #define N 2600 9 int n,m; 10 struct Node{ 11 int l,r; 12 bool friend operator < (Node a,Node b){ 13 return a.r>b.r; 14 } 15 }cow[N]; 16 struct Node1{ 17 int x,num; 18 }p[N]; 19 bool cmp(Node a,Node b){ 20 return a.l<b.l; 21 } 22 bool cmp1(Node1 a,Node1 b){ 23 return a.x<b.x; 24 } 25 int main() 26 { 27 while(scanf("%d%d",&n,&m)==2){ 28 29 for(int i=0;i<n;i++){ 30 scanf("%d%d",&cow[i].l,&cow[i].r); 31 } 32 for(int i=0;i<m;i++){ 33 scanf("%d%d",&p[i].x,&p[i].num); 34 } 35 sort(cow,cow+n,cmp); 36 sort(p,p+m,cmp1); 37 38 //for(int i=0;i<v.size();i++){ 39 // printf("---%d\n",v[i]); 40 //} 41 42 priority_queue<Node>q; 43 44 int k=0; 45 int ans=0; 46 for(int i=0;i<m;i++){ 47 while(k<n && cow[k].l<=p[i].x){ 48 q.push(cow[k]); 49 k++; 50 } 51 52 int w=0; 53 while(!q.empty()){ 54 55 if(w>=p[i].num) break; 56 57 Node tmp=q.top(); 58 if(tmp.r>=p[i].x){ 59 q.pop(); 60 ans++; 61 w++; 62 } 63 else{ 64 q.pop(); 65 } 66 67 } 68 } 69 printf("%d\n",ans); 70 } 71 return 0; 72 } View Code |
转载于:https://www.cnblogs.com/UniqueColor/p/4768231.html
poj 3614 Sunscreen(优先队列+贪心)相关推荐
- 【POJ 3614 Sunscreen】贪心 优先级队列
题目链接:http://poj.org/problem?id=3614 题意:C头牛去晒太阳,每头牛有自己所限定的spf安全范围[min, max]:有L瓶防晒液,每瓶有自己的spf值和容量(能供几头 ...
- POJ - 3614 Sunscreen(贪心/二分图最大匹配-多重匹配/网络流-最大流)
题目链接:点击查看 题目大意:给出n头奶牛,奶牛们现在要晒太阳,每头奶牛需要[l,r]区间内的光照强度,现在有m种防晒霜,每种防晒霜可以让奶牛接受到val数值的光照强度,然后每种防晒霜只有num个,现 ...
- POJ 3614 Sunscreen
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12907 Accepted: 4534 Descri ...
- 【贪心】Sunscreen(poj 3614/luogu 2887)
Sunscreen poj 3614 luogu 2887 题目大意: 有n个人,每个人要求选一个价值在minniminn_iminni到maxximaxx_imaxxi的物品,现在有m件物品,每 ...
- LeetCode 1642. 可以到达的最远建筑(二分查找 / 优先队列贪心)
文章目录 1. 题目 2. 解题 2.1 二分查找 2.2 优先队列+贪心 1. 题目 给你一个整数数组 heights ,表示建筑物的高度.另有一些砖块 bricks 和梯子 ladders . 你 ...
- 【CF 732E】Sockets(优先队列+贪心)
[CF 732E]Sockets(优先队列+贪心) 题目大意: n台电脑,m个供电器. 每台电脑和每个供电器都有电量,当电脑i的电量和供电器j电量相同时,可以连接供电. 现在提供变压器,可以连接到供电 ...
- POJ - 3190 Stall Reservations(贪心+优先队列优化)
题目链接:点击查看 题目大意:有n头牛在畜栏中吃草,每个畜栏在同一时间段只能提供给一头牛吃草,所以可能会需要多个畜栏,给定N头牛和每头牛开始吃草和结束吃草的时间,每头牛在给定时间段内会一直吃草,求需要 ...
- POJ 2431 Expedition(贪心+优先队列)
题目链接:点击打开链接 贪心策略: 当车燃料没有耗尽的时候,就将沿途路过的加油站全都入队 因为这些加油站是可路过的,且车的邮箱容量无限,所以我们可以看作这些加油站随时都能给车提供油 为了使加油次数最少 ...
- BZOJ 2288: 【POJ Challenge】生日礼物 优先队列+贪心+链表
这题看别人题解的 这题说可以转换成数据备份. 这题可以把一段同号的数并成一个数,那么就变成了一个正负交替的序列,然后把头尾的负数去掉. 然后就是把所有的正值都加起来,并统计正数的段数cnt,如cnt& ...
最新文章
- 利用ISA Server 2006服务器阵列构建高性能、高可靠的企业防火墙
- python matplotlib散点图-python matplotlib更新函数的散点图
- android fragment界面滑动切换效果,Android App中使用ViewPager+Fragment实现滑动切换效果...
- linux中umask的使用
- freemarker -自定义指令
- spring boot target文件夹_Boot之Boot Shell
- 【四足机器人那些事儿】MiniCheetah中的MPC控制
- 怎样保护计算机桌面不被更改,电脑保护屏幕怎么设置
- 吴恩达反向传播算法推导,吴恩达卷积神经网络ppt
- uniapp中使用阿里云视频点播功能
- php aes 256 加解密,PHP完整的AES加解密算法使用及例子(256位)
- 26岁想转行做程序员是否可行?
- 2.0 案例2:爬取房源信息以及分析房价
- MySQL数据库-删除表中的数据详解
- ubuntu16安装python3.6
- 【KITTI数据集】VELODYNE POINT CLOUD-激光雷达点云BIN文件读取和显示-OPEN3D
- 关于flash安装失败的解决办法
- 快速入门 | 篇十一: 正运动技术运动控制器中断的应用​
- IT部落格网页设计图
- 释放内存资源,我用empty.exe命令