hiho一下 第148周
题目1 : Font Size
描述
Steven loves reading book on his phone. The book he reads now consists of N paragraphs and the i-th paragraph contains ai characters.
Steven wants to make the characters easier to read, so he decides to increase the font size of characters. But the size of Steven's phone screen is limited. Its width is W and height is H. As a result, if the font size of characters is S then it can only show ⌊W / S⌋ characters in a line and ⌊H / S⌋ lines in a page. (⌊x⌋ is the largest integer no more than x)
So here's the question, if Steven wants to control the number of pages no more than P, what's the maximum font size he can set? Note that paragraphs must start in a new line and there is no empty line between paragraphs.
输入
Input may contain multiple test cases.
The first line is an integer TASKS, representing the number of test cases.
For each test case, the first line contains four integers N, P, W and H, as described above.
The second line contains N integers a1, a2, ... aN, indicating the number of characters in each paragraph.
For all test cases,
1 <= N <= 103,
1 <= W, H, ai <= 103,
1 <= P <= 106,
There is always a way to control the number of pages no more than P.
输出
For each testcase, output a line with an integer Ans, indicating the maximum font size Steven can set.
- 样例输入
-
2
1 10 4 3
10
2 10 4 3
10 10 - 样例输出
-
3
2
题目很简单,就是找最大符合条件的p。把题目看懂,枚举似乎也可以过。
这里,我用二分省了一部分时间,也许有更好的优化。。菜鸟我就没有去想了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+;
ll T, n, w, h, pp;
ll p[maxn]; bool ok(ll s) {
ll c_num = w/s, l_num = h/s, cnt = ;
if( c_num<= || l_num<= ) return false;
for(int i=; i<n; i++) {
if( c_num == ) cnt += p[i];
else cnt += (p[i]+c_num-)/c_num;
}
return ( cnt + l_num - ) / l_num <= pp;
} int main(){
cin >> T;
while( T -- ) {
cin >> n >> pp >> w >> h;
for(int i=; i<n; i++) cin >> p[i];
ll l = , r = min(w, h), m;
while( l < r ) {
m = (l+r)/;
if( ok(m) ) l = m+;
else r = m-;
}
while( !ok(l) ) l--;
cout << l << endl;
}
return ;
}
hiho一下 第148周的更多相关文章
- 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point
// 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point // 思路:直接暴力绝对T // 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点.枚举x的范围,再 ...
- hiho一下 第115周:网络流一•Ford-Fulkerson算法 (Edmond-Karp,Dinic,SAP)
来看一道最大流模板水题,借这道题来学习一下最大流的几个算法. 分别用Edmond-Karp,Dinic ,SAP来实现最大流算法. 从运行结过来看明显SAP+当前弧优化+gap优化速度最快. hi ...
- 【hiho一下第77周】递归-减而治之 (MS面试题:Koch Snowflake)
本题是一道微软面试题,看起来复杂,解出来会发现其实是一个很简单的递归问题,但是这道题的递归思路是很值得我们反复推敲的. 原题为hihocoder第77周的题目. 描述 Koch Snowflake i ...
- hiho一下 第207周
题目1 : The Lastest Time 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is latest time you can make with ...
- hiho一下第128周 后缀自动机二·重复旋律5
#1445 : 后缀自动机二·重复旋律5 时间限制:10000ms 单点时限:2000ms 内存限制:512MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为一段数构成的数 ...
- 【hiho一下】第一周 最长回文子串
题目1:最长回文子串 题目原文:http://hihocoder.com/contest/hiho1/problem/1 [题目解读] 题目与 POJ 3974 palindrome 基本同样.求解最 ...
- Solution: 最近公共祖先·一 [hiho一下 第十三周]
题目1 : 最近公共祖先·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho最近发现了一个神奇的网站!虽然还不够像58同城那样神奇,但这个网站仍然让小Ho乐在其中 ...
- hiho一下十六周 RMQ-ST算法
RMQ-ST算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在美国旅行了相当长的一段时间之后,终于准备要回国啦!而在回国之前,他们准备去超市采购一些当 ...
- hiho一下 第九十七周 数论六·模线性方程组
题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军 ...
随机推荐
- 关于Go,你可能不注意的7件事
转自: https://tonybai.com/2015/09/17/7-things-you-may-not-pay-attation-to-in-go/ Go以简洁著称,但简洁中不乏值得玩味的小细 ...
- golang gui library 库
andlabs/ui已经重写,稳定性增强,但是组件很少,只提供了几种基础的控件,慎用.gxui死了,别用.linuxdeepin转QT了,所以…… windows系统最好的选择是walk. 首先,写w ...
- Spark创建空的DataFrame
前言 本文主要给出Spark创建空的DataFrame的代码示例,这里讲的空的DataFrame主要指有列名(可以自己随意指定),但是没有行的DataFrame,因为自己在开发过程中有这个需求,之前并 ...
- [django]modelform实现的多文件上传
实现效果 代码 models.py from django.db import models import uuid class UUIDTools(object): ""&quo ...
- sort(排序) qsort(快排) bsearch(二分查找)
sort: 一.对int类型数组排序 int a[100]; int cmp ( int a , int b ) //不必强制转换 { return a < b;//升序排列. } sort ( ...
- Django 框架 基本知识
一.什么事web框架 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支持结构,使用框架可以使我们快速开发特定的系统,简单来说,就是讲实现方式的底层结构进行封装,提供相应的 ...
- VirtualBox如何扩展虚拟机Ubuntu的硬盘容量-转
https://blog.csdn.net/ouyang_peng/article/details/53261599 摘录要点: 扩展 VBoxManage modifyhd YOUR_HARD_DI ...
- cocos2dx - Lua 语言
快捷注释: - -[[ print(10) - ->10 - - 不起作用(因为这是注释) - -]] 当重新启用这段代码时,只需在一次行行首添加一个连接字符即可: - - -[[ print ...
- web.config或App.config中AttachDBFilenamex相对路径问题
<add name="employeeManagerConnectionString" connectionString="Data Source=.\SQLExp ...
- WebSocket.之.基础入门-后端响应消息
WebSocket.之.基础入门-后端响应消息 在<WebSocket.之.基础入门-前端发送消息>的代码基础之上,进行添加代码.代码只改动了:TestSocket.java 和 inde ...