题目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. C 表達式及返回值

    以下程序的输出结果是__A____. #include<stdio.h> main() { ,j=; printf("%d,%d\n",++i,j--); } A., ...

  2. Jsp与Servlet面试题

    一.jsp有哪些内置对象作用分别是什么  答:JSP共有以下9种基本内置组件(可与ASP的6种内部组件相对应): request  用户端请求,此请求会包含来自GET/POST请求的参数  respo ...

  3. U盘安装ubuntu 16.04 遇到 gfxboot.c32:not a COM32R image boot 的解决方法

    从U盘启动的时候出现了gfxboot.c32:not a COM32R image的问题,经过研究发现按下Tab键,会出现live live-install check memtest hd main ...

  4. 服务请求比较慢SYN flooding

    服务请求比较慢 dmesg 查看日志,发现SYN flooding 问题,某一端口居多 内核输出“TCP: Possible SYN flooding on port”信息,在内核syncookie机 ...

  5. 遇到CloudFlare邮箱混淆,如何解密?

    <script type="text/javascript">$(function() { $(".__cf_email__").each(func ...

  6. 修改CentOS的IP地址

    一.临时修改 命令:ifconfig eth0 192.168.1.147 重启或者关机后,iP地址将会恢复到修改之前的状态. 二.永久修改 命令: vi /etc/sysconfig/network ...

  7. 利用TensorFlow实现线性回归模型

    准备数据: import numpy as np import tensorflow as tf import matplotlib.pylot as plt # 随机生成1000个点,围绕在y=0. ...

  8. centos7挂载新加4T硬盘到/home目录

    以下操作均在root环境下运行. 1.查看硬盘 # fdisk -l 发现硬盘为/dev/sdb 大小4T 2.如果此硬盘以前有过分区,则先对磁盘格式化: # mkfs -t ext4 /dev/sd ...

  9. iOS UI基础-9.1 UITableView 团购

    概述 接下来,我们要做的是团购界面的设计,最张要实现的效果图及项目结构图      团购数据的展示 思路: 系统自带的tableCell不能展示三个文本,不能满足条件,自定义tableCell 每一个 ...

  10. MACD各分时背离所对应的时间

    MACD各分时背离所对应的时间 5分钟背离结构——2小时.           15分钟背离结构——一天半(6小时).           30分钟背离结构——3天(12小时).            ...