Problem D. Ice Cream Tower
题解:二分加贪心,,,二分答案,然后进行判断,判断的时候,首先给每一组配一个最大的球,然后在向每一组里面填球,注意填球的时候要按组进行,每一组先填一个,然后更新每一组内的最小值,方便下一次寻找。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3E5+;
ll arr[N];
ll b[N];
bool mark[N];
int n,m;
bool judge(int x){
int pos= n-;
for(int i=;i<=x;i++) b[i]=arr[pos],pos--;//先给每一组添加一个底; for(int i=;i<=m;i++){//每一组还需要m-1个 for(int j=;j<=x;j++){
int flag=-;
ll x1=b[j];
x1>>=; for(int k=pos;k>=;k--){//在商店中剩余的物品里面挑选出第一个小于小于等于前一个的一半的物品
if(arr[k]<=x1){
flag=k;
b[j] = arr[k];
pos=k-;//更新一下pos
break;
}
} if(flag==-) return ;//找不到的话直接返回0
}
} return ;
}
void solve(int xx){
scanf("%d%d",&n,&m);
for(int i=;i<n;i++) scanf("%lld",&arr[i]);
sort(arr,arr+n);
int l=;
int r=n;
int ans=;
while(l<=r){
int mid=(l+r)/;
if(judge(mid)){
ans=max(ans,mid);
l=mid+;
}
else r=mid-;
}
printf("Case #%d: %d\n",xx,ans);
} int main(){
int t;
cin>>t;
for(int i=;i<=t;i++) solve(i);
return ;
}
Problem D. Ice Cream Tower的更多相关文章
- Ice Cream Tower
2017-08-18 21:53:38 writer:pprp 题意如下: Problem D. Ice Cream Tower Input file: Standard Input Output f ...
- 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心
/** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...
- Ice Cream Tower(The 2016 ACM-ICPC Asia China-Final Contest 二分&贪心)
题目: Mr. Panda likes ice cream very much especially the ice cream tower. An ice cream tower consists ...
- Gym 101194D Ice Cream Tower
被一道数位DP折磨得欲仙欲死之后,再做这道题真是如同吃了ice cream一样舒畅啊 #include<bits/stdc++.h> using namespace std; #defin ...
- Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- Gym 101194E / UVALive 7901 - Ice Cream Tower - [数学+long double][2016 EC-Final Problem E]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- Ice Cream Tower Gym - 101194D (贪心 + 二分 )
题目链接 : https://cn.vjudge.net/problem/Gym-101194D 题目大意 : 给你n个冰激凌球,让你用这些冰激凌球去垒冰激凌,要求是下面的这一个必须是他上面一个的两倍 ...
- The 2016 ACM-ICPC Asia China-Final D. Ice Cream Tower 二分 + 贪心
题目大意: 对于给出的n个冰激凌球的大小,满足下面的球的大小是上一个的至少2倍,对于给出的k(由k的冰激凌球才能算作一个冰激凌塔),问n个冰激凌球可以最多堆出多少个高度为k的冰激凌塔 题目分析: 对于 ...
- HackerRank Ice Cream Parlor
传送门 Ice Cream Parlor Authored by dheeraj on Mar 21 2013 Problem Statement Sunny and Johnny together ...
随机推荐
- 微信小程序api封装
写多 之后,吸取之前的经验,瞎写了一个简单的封装api,有幸看到的朋友,就随便看看哈,如果能给到你帮助就一直棒了,额呵呵呵! 新建constant.js和api.js文件 在constant.js中统 ...
- SpringBoot2 + Druid + Mybatis 多数据源动态配置
在大数据高并发的应用场景下,为了更快的响应用户请求,读写分离是比较常见的应对方案.读写分离会使用多数据源的使用.下面记录如何搭建SpringBoot2 + Druid + Mybatis 多数据源配 ...
- 终极解决方案之——Centos7由于误删或更新python导致 No module named yum
之前由于不懂yum和python之间的关系,因为一直在学python3,看到系统里/usr/lib下的python2我就直接删了,结果... 可能还有人是因为python升级的原因,即系统自带的pyt ...
- Docker镜像拉取慢的解决方法
镜像加速器配置: 下文配置引用于阿里云说明文档:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 1. 安装/升级Docker客户 ...
- xgboost安装与原理
1.xgboost库的安装 先在网址https://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost 中下载whl文件,注意一定要下载跟自己当前安装Python版 ...
- 使用Keras进行深度学习:(二)CNN讲解及实践
欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! 现今最主流的处理图像数据的技术当属深度神经网络了,尤其是卷积神经网 ...
- Android | 教你如何用华为HMS MLKit SDK 三十分钟在安卓上开发一个微笑抓拍神器
Android | 只要三十分钟就可以在手机上开发一个微笑抓拍神器!!! 前言 前段时间Richard Yu在发布会上给大家介绍了华为HMS Core4.0,回顾发布会信息请戳: 华为面向全球发布HM ...
- Ubuntu复制粘贴快捷键
复制:[Ctrl+Insert] 粘贴:[Shitf+Insert]
- 玩转redis-简单消息队列
使用go语言基于redis写了一个简单的消息队列 源码地址 使用demo redis的 list 非常的灵活,可以从左边或者右边添加元素,当然也以从任意一头读取数据 添加数据和获取数据的操作也是非常简 ...
- B. The Monster and the Squirrel
B. The Monster and the Squirrel Ari the monster always wakes up very early with the first ray of the ...