hihoCoder#1095(二分搜索)
描述
Little Hi and Little Ho are playing a drinking game called HIHO. The game comprises N rounds. Each round, Little Hi pours T milliliter of water into Little Ho's cup then Little Ho rolls a K-faces dice to get a random number d among 1 to K. If the remaining water in Little Ho's cup is less than or equal to d milliliter Little Hi gets one score and Little Ho drinks up the remaining water, otherwise Little Ho gets one score and Little Ho drinks exactly d milliliter of water from his cup. After N rounds who has the most scores wins.
Here comes the problem. If Little Ho can predict the number d of N rounds in the game what is the minimum value of T that makes Little Ho the winner? You may assume that no matter how much water is added, Little Ho's cup would never be full.
输入
The first line contains N(1 <= N <= 100000, N is odd) and K(1 <= K <= 100000).
The second line contains N numbers, Little Ho's predicted number d of N rounds.
输出
Output the minimum value of T that makes Little Ho the winner.
- 样例输入
-
5 6
3 6 6 2 1 - 样例输出
-
4 思路:求最值时考虑使用二分搜索。
#include <iostream>
using namespace std;
const int MAXN=;
const int INF=0x3f3f3f3f;
int n,k;
int d[MAXN];
bool test(int T)
{
int cup=;
int hi_score=;
int ho_score=;
for(int i=;i<n;i++)
{
cup+=T;
if(cup<=d[i])
{
hi_score++;
cup=;
}
else
{
ho_score++;
cup-=d[i];
}
}
return ho_score>hi_score;
}
int main()
{
cin>>n>>k;
for(int i=;i<n;i++)
{
cin>>d[i];
}
int l=,r=INF;
while(r-l>)
{
int mid=(l+r)>>;
if(test(mid))
{
r=mid;
}
else
{
l=mid;
}
}
cout<<r<<endl;
return ;
}
hihoCoder#1095(二分搜索)的更多相关文章
- Hihocoder #1095 : HIHO Drinking Game (微软苏州校招笔试)( *【二分搜索最优解】)
#1095 : HIHO Drinking Game 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playin ...
- hihoCoder #1053 : 居民迁移(贪心,二分搜索,google在线技术笔试模拟)
#1053 : 居民迁移 时间限制:3000ms 单点时限:1000ms 内存限制:256MB 描述 公元2411年,人类开始在地球以外的行星建立居住点.在第1326号殖民星上,N个居住点分布在一条直 ...
- hihocoder 二分·二分答案【二分搜索,最大化最小值】 (bfs)
题目 这道题做了几个小时了都没有做出来,首先是题意搞了半天都没有弄懂,难道真的是因为我不打游戏所以连题都读不懂了? 反正今天是弄不懂了,过几天再来看看... 题意:一个人从1点出发到T点去打boss, ...
- hihocoder hiho第38周: 二分·二分答案 (二分搜索算法应用:二分搜索值+bfs判断可行性 )
题目1 : 二分·二分答案 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在上一回和上上回里我们知道Nettle在玩<艦これ>,Nettle在整理好舰队之后 ...
- [LeetCode] Largest BST Subtree 最大的二分搜索子树
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...
- hihocoder -1121-二分图的判定
hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...
- Hihocoder 太阁最新面经算法竞赛18
Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...
- hihoCoder太阁最新面经算法竞赛15
hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...
- 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II
http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...
随机推荐
- 20145230 《Java程序设计》第8周学习总结
20145230 <Java程序设计>第8周学习总结 教材学习内容 NIO与NIO2 NIO使用频道(Channel)来衔接数据节点,在处理数据时,NIO可以设定缓冲区(Buffer)容量 ...
- Centos7.4 Nginx反向代理+负载均衡配置
Ningx是一款高性能的HTTP和反向代理服务器,配置起来也比较简单. 测试环境: 172.16.65.190 Nginx-反向代理 172.16.65.191 Ningx-Web 172.16.65 ...
- 【bzoj3240 && 洛谷P1397】矩阵游戏[NOI2013](矩阵乘法+卡常)
题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3240 这道题其实有普通快速幂+费马小定理的解法……然而我太弱了,一开始只想到了矩阵乘法的 ...
- python进阶02
1.import导入模块 import sys sys.path:显示的是:从显示目录中查找要导入的模块文件. 程序执行时导入模块路径:sys.path.append('/home/itcast/xx ...
- MapReduce-输入分片与记录
一个输入分片(split)就是一个由单个map操作来处理的输入块.每一个map操作只处理一个输入分片.每个分片被划分为若干个记录,每条记录就是一个键值对,map一个接一个地处理记录.输入分片和记录都是 ...
- YARN作业提交流程剖析
YARN(MapReduce2) Yet Another Resource Negotiator / YARN Application Resource Negotiator对于节点数超出4000的大 ...
- nodejs 语法很特别的地方
1. 不过我们之前说过了有 this 和没 this 的时候作用域不同,那个参数只是作用于构造函数中,而加了 this 的那个则是成员变量.用一个 this 就马上区分开来他们了,所以即使同名也没关系 ...
- 内网批量测试登录机器工具,并且dir 目标机器c盘
// Ipc.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #include <w ...
- ANT+JMETER集成3 (添加邮件附件)
在build.xml文件<email>中加入下面几行代码 <fileset dir="C:\apache-jmeter-3.0\html/"> <in ...
- Liberty版本更新日志中文版本
新功能 API · 为所有的endpoints默认使用v2.1的API,v2.0和v1.1使用了新的兼容模式,对已经使用API的用户过渡更平稳.( https://blueprints.launch ...