神奇的传送门

现在给了一个冰箱,有两格宽,H格高,还有N瓶牛奶,每个牛奶都有一个高度,求最多能放进前几个瓶子


二分枚举,贪心验证。当前这些瓶子中,最高的能放下,这组序列才有可能放下。
二分枚举前n个瓶子,将前n个瓶子降序排列,选取两个之间最高的,判断这组是否能合法加入。


#include <stdio.h>
#include <climits>
#include <cstring>
#include <time.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <vector>
#include <string>#define INF 0x3f3f3f3f
#define ll long long
#define Pair pair<int,int>
#define re return#define getLen(name,index) name[index].size()
#define mem(a,b) memset(a,b,sizeof(a))
#define Make(a,b) make_pair(a,b)
#define Push(num) push_back(num)
#define rep(index,star,finish) for(register int index=star;index<finish;index++)
#define drep(index,finish,star) for(register int index=finish;index>=star;index--)
using namespace std;int N,H;
vector<int> bottle;
bool judge(int mid);
inline bool cmp(const int &a,const int &b);
int main(){ios::sync_with_stdio(false);cin.tie(NULL);int temp;cin>>N>>H;rep(i,0,N){cin>>temp;bottle.Push(temp);}int inf=0,sup=N+1;while(inf+1<sup){int mid=inf+(sup-inf)/2;if(judge(mid)){inf=mid;}else{sup=mid;}}cout<<inf<<endl;re 0;
}
bool judge(int mid){vector<int> store(bottle.begin(),bottle.begin()+mid);sort(store.begin(),store.end(),cmp);ll height=0;for(register int i=0;i<store.size();i+=2){height+=store[i];if(height>H)re false;}re true;
}
inline bool cmp(const int &a,const int &b){re a>b;
}

codeforces1119B. Alyona and a Narrow Fridge 贪心相关推荐

  1. B. Alyona and a Narrow Fridge 【 思维题 】

    B. Alyona and a Narrow Fridge Codeforces Global Round 2 &:这题看到了一种很简单的做法,于是按照敲一波,比原来打的好看多了. 题意:给你 ...

  2. B. Alyona and a Narrow Fridge

    题目链接 Alyona has recently bought a miniature fridge that can be represented as a matrix with h rows a ...

  3. Codeforces Global Round 2 B. Alyona and a Narrow Fridge

    题意:有一个冰箱,你可以放若干个隔板,将冰箱分成高度不等的若干层,然后再给你n瓶高度不一样的牛奶,你要按顺序放尽可能多的牛奶,每层牛奶最多只能放两瓶,并且牛奶瓶的高度不能超过该层的长度. 思路:之前两 ...

  4. Codeforces Global Round 2 B. Alyona and a Narrow Fridge(二分)

    题目链接:https://codeforces.com/contest/1119/problem/B        题意是给了n个水瓶,一个高度h,现在要把这n个水瓶按顺序放到h*2的柜子里,柜子里可 ...

  5. B. Alyona and a Narrow Fridge( Codeforces Global Round 2)二分

    题目地址:http://codeforces.com/contest/1119/problem/B #include <iostream> #include <cstdio> ...

  6. Codeforces Global Round 2(CF1119)

    这场题目设置有点问题啊,难度:Div.2 A->Div.2 B->Div.2 D->Div.2 C->Div.2 D->Div.1 D-> Div.1 E-> ...

  7. cf 、B. Fridge Lockers(思维 + 贪心)

    题意:有n个冰箱,然后m个锁链,每条锁链两头都连着冰箱,然后让你每个冰箱都至少连着两条锁链指向不同冰箱.买锁链的钱是两个冰箱重量的和,问最少花费多少钱可以满足,如果满足输出最小花费,否则,输出-1. ...

  8. 《贪心算法》— NYOJ 贪心算法题目汇总(一)

    题目6 题目信息 运行结果 本题排行 讨论区 喷水装置(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为 ...

  9. 算法设计与分析第3章 贪心算法

    第4章 贪心算法 贪心算法总是作出在当前看来最好的选择.也就是说贪心算法并不从整体最优考虑,它所作出的选择只是在某种意义上的局部最优选择. 贪心算法的基本要素 1.贪心选择性质 所谓贪心选择性质是指所 ...

最新文章

  1. 联想重启乐檬?5G时代手机双品牌战略带来变局
  2. 作业三——原型化系统——外卖app
  3. mybatis04--Mapper动态代理实现
  4. JavaSE(六)——Object类、克隆方法
  5. 【爬虫、算法】基于Dijkstra算法的武汉地铁路径规划!
  6. Clion 远程同步设置
  7. Python档案袋( 面向对象 )
  8. YBTOJ:字符匹配(KMP)
  9. linux 输出后面几列内容,Linux下使用awk如何获取关键字所在字段号,第几列,以及打印这个字段之后的所有字段?...
  10. 使用Scrapy框架编写爬虫
  11. RGB vs YCbCr(YUV)
  12. python自定义函数的关键字_python学习之--自定义函数:
  13. Java虚拟机对内部锁的四种优化方式
  14. Linux内核使用的字符串转整形数和16进制数
  15. linux内核源码分析--内核启动之,Linux内核源码分析之setup_arch (二)
  16. 《信号与系统学习笔记》—信号与系统的时域和频域特性(二)
  17. 啊哈C语言 第二章 【代码】【习题答案】
  18. 怎么区分zh和ch_怎样区分zh,ch,sh与z,c,s
  19. lcd调色板工作原理详解
  20. 端午节送点话费给大家,千万别错过!

热门文章

  1. from..import 语句
  2. HTML Label标签使用
  3. 我猜,你还不知道数据标注公司在做什么吧?
  4. 艺赛旗(RPA)Python 学习之异常
  5. 外星人跑深度学习_外星人带你搞基?这部12年的动画绝了
  6. linux环境下tomcat配置PHP
  7. message from server: “Host ‘DESKTOP-FAJUM7V‘ is not allowed to connect to this MySQL server“
  8. tk.mybatis.mapper.MapperException: 无法获取实体类com.leyou.work.entity.Brand对应的表名!
  9. 无人值守安装linux7,kickstart无人值守安装CentOS7
  10. 如何做一个小程序商城,需要多少钱