题目1 : Font Size

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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周的更多相关文章

  1. 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point

    // 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point // 思路:直接暴力绝对T // 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点.枚举x的范围,再 ...

  2. hiho一下 第115周:网络流一•Ford-Fulkerson算法 (Edmond-Karp,Dinic,SAP)

    来看一道最大流模板水题,借这道题来学习一下最大流的几个算法. 分别用Edmond-Karp,Dinic ,SAP来实现最大流算法. 从运行结过来看明显SAP+当前弧优化+gap优化速度最快.   hi ...

  3. 【hiho一下第77周】递归-减而治之 (MS面试题:Koch Snowflake)

    本题是一道微软面试题,看起来复杂,解出来会发现其实是一个很简单的递归问题,但是这道题的递归思路是很值得我们反复推敲的. 原题为hihocoder第77周的题目. 描述 Koch Snowflake i ...

  4. hiho一下 第207周

    题目1 : The Lastest Time 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is latest time you can make with ...

  5. hiho一下第128周 后缀自动机二·重复旋律5

    #1445 : 后缀自动机二·重复旋律5 时间限制:10000ms 单点时限:2000ms 内存限制:512MB 描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一个音乐旋律被表示为一段数构成的数 ...

  6. 【hiho一下】第一周 最长回文子串

    题目1:最长回文子串 题目原文:http://hihocoder.com/contest/hiho1/problem/1 [题目解读] 题目与 POJ 3974 palindrome 基本同样.求解最 ...

  7. Solution: 最近公共祖先·一 [hiho一下 第十三周]

    题目1 : 最近公共祖先·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho最近发现了一个神奇的网站!虽然还不够像58同城那样神奇,但这个网站仍然让小Ho乐在其中 ...

  8. hiho一下十六周 RMQ-ST算法

    RMQ-ST算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在美国旅行了相当长的一段时间之后,终于准备要回国啦!而在回国之前,他们准备去超市采购一些当 ...

  9. hiho一下 第九十七周 数论六·模线性方程组

    题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军 ...

随机推荐

  1. element-dialog封装成子组件

    1.父组件 <template> <card-layout :title="L('Users')" :actions="actions" @c ...

  2. 【LeetCode每天一题】Reverse String

    Write a function that reverses a string. The input string is given as an array of characters char[]. ...

  3. Xcode 运行 Signing for "XXXXXX" requires selecting either a development team or a provisioning profile. Select a development team or a provisioning profile in the project editor

    Signing for "XXXXXX" requires selecting either a development team or a provisioning profil ...

  4. What is the reason for - java.security.spec.InvalidKeySpecException: Unknown KeySpec type: java.security.spec.ECPublicKeySpec

    支付中心Project重构完成,经过本地测试,并未发现问题.发布到测试环境后,测试发现请求光大扫码https接口时,出现了如下的异常: javax.net.ssl.SSLException: Serv ...

  5. unity3d-角色控制器续

    自学是一个坚持和寂寞的过程,写博客更是一个总结与成长的过程,加油! 角色控制器续 之前学习了角色漫游,但里面有很多效果都不是我想要的.只有自己的动手实践了才能理会其中的奥妙.所以我又琢磨了许久. 为了 ...

  6. InstallShield 读注册表函数 RegDBGetKeyValueEx ()执行失败

    注: rtn = RegDBGetKeyValueEx(szKey, szNumName, nvType, svNumValue, nvSize); 调用失败如果这个函数的几个参数没有初始化的值,调用 ...

  7. linux工作目录切换命令

    1.pwd命令 pwd命令用于显示用户当前所处的工作目录,格式为“pwd [选项]”. 2.cd命令 cd命令用于切换工作路径,格式为“cd [目录名称]”. 这个命令应该是最常用的一个Linux命令 ...

  8. Rpgmakermv(33) Mog_PictureGallery

    ============================================================================= +++ MOG - Picture Gall ...

  9. 重建二叉树POJ2255

    重建二叉树 给定一棵二叉树的前序遍历和中序遍历的结果,求其后序遍历. 输入输入可能有多组,以EOF结束.每组输入包含两个字符串,分别为树的前序遍历和中序遍历.每个字符串中只包含大写字母且互不重复.输出 ...

  10. html5-label标签

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...