#1288 : 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 解题思路:
字体的最大值是min(H,W),依次枚举出所有的可能,算出每段字需要要多少行,让后算出总共需要多少行,再计算需要多少页。 AC代码
 #include "iostream"
#include "algorithm"
#define MAX 1000 using namespace std; int main(){ int a[MAX];
int T; cin >> T;
while (T--){
int N, P, W, H; //总共N段,不超过P页,WH长宽,T组数据 cin >> N >> P >> W >> H; for (int i = ; i < N; i++){
cin >> a[i];
} int ans = min(H, W);
int perline, allline, perpg,lineper,page; //perpg每页行数,perline 每段行数,lineper每行字数 for (int i = ans; ans >= ; i--)
{
allline = ;
lineper = W / i; //每行字数
for (int j = ; j < N; j++){
perline = a[j] / lineper;
if (a[j] % lineper!=)
perline ++;
allline += perline;
}
perpg = H / i; //perpg每页行数 page = allline / perpg; //当前字体大小时需要的页数 if (allline % perpg != )
page++; if (page <= P){
cout << i << endl;
break;
}
}
}
return ;
}
终于AC了,之前怎么都过不了,显示RE,返回去又把题目看了一遍,原来他MAX是10的3方,我设的100,数据集限定小了,所以一直RE

hiho #1288 微软2016.4校招笔试题 Font Size的更多相关文章

  1. 剑指Offer——美团内推+校招笔试题+知识点总结

    剑指Offer--美团内推+校招笔试题+知识点总结 前言 美团9.9内推笔试.9.11校招笔试,反正就是各种虐,笔试内容如下: 知识点:图的遍历(DFS.BFS).进程间通信.二叉查找树节点的删除及中 ...

  2. 剑指Offer——CVTE校招笔试题+知识点总结(Java岗)

    剑指Offer(Java岗)--CVTE校招笔试题+知识点总结 2016.9.3 19:00参加CVTE笔试,笔试内容如下: 需要掌握的知识:Linux基本命令.网络协议.数据库.数据结构. 选择题 ...

  3. 2016最新Java笔试题集锦

    更新时间:2015-08-13         来源:网络         投诉删除 [看准网(Kanzhun.com)]笔试题目频道小编搜集的范文“2016最新Java笔试题集锦”,供大家阅读参考, ...

  4. 剑指Offer——腾讯+360+搜狗校招笔试题+知识点总结

    剑指Offer--腾讯+360+搜狗校招笔试题+知识点总结 9.11晚7:00,腾讯笔试.选择题与编程.设计题单独计时. 栈是不是顺序存储的线性结构啊? 首先弄明白两个概念:存储结构和逻辑结构. 数据 ...

  5. 剑指Offer——京东校招笔试题+知识点总结

    剑指Offer--京东校招笔试题+知识点总结 笔试感言 经过一系列的笔试,发觉自己的基础知识还是比较薄弱的,尤其是数据结构和网络,还有操作系统.工作量还是很大的.做到精确制导的好方法就是在网上刷题,包 ...

  6. 2016京东Android研发校招笔试题

    一.选择题汇总,具体的记不住啦.. 1.计网:ip的网络前缀.SNMP(报文组成):http://blog.csdn.net/shanzhizi/article/details/11606767 参考 ...

  7. 微软2017校招笔试题3 registration day

    题目 It's H University's Registration Day for new students. There are M offices in H University, numbe ...

  8. 微软2017校招笔试题2 composition

    题目 Alice writes an English composition with a length of N characters. However, her teacher requires ...

  9. 微软2014校招笔试题-String reorder

    Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB Description For this question, your pro ...

随机推荐

  1. SDAutolayout图片大小根据数量变化

    只需要在自定义的PhotoContainerView中做一下判断就可以了 ) { [self setupAutoWidthFlowItems:[temp copy] withPerRowItemsCo ...

  2. navigationBar设置透明度

    将NavigationBar设置透明(仅将指定视图控制器进行透明处理),步骤如下:1.在视图控制器的头文件中实现UINavigationControllerDelegate,例如:@interface ...

  3. android常用的弹出提示框

    我们在平时做开发的时候,免不了会用到各种各样的对话框,相信有过其他平台开发经验的朋友都会知道,大部分的平台都只提供了几个最简单的实现,如果我们想实现自己特定需求的对话框,大家可能首先会想到,通过继承等 ...

  4. 超市管理系统—NABCD模型

    1) N (Need 需求) 需求分析: 超市的数据和业务越来越庞大,而计算机就是一种高效的管理系统,这就需要我们把超市的管理与计算机结合起来,从而超市管理系统应运而生.依靠现代化的计算机信息处理技术 ...

  5. Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合

    题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...

  6. 【UVA 1451】Average

    题 题意 求长度为n的01串中1占总长(大于L)的比例最大的一个子串起点和终点. 分析 前缀和s[i]保存前i个数有几个1,[j+1,i] 这段区间1的比例就是(s[i]-s[j])/(i-j),于是 ...

  7. firefox(ff)下无法显示bootstrap图标问题的解决方案(转)

    原文链接: http://www.th7.cn/web/html-css/201502/82548.shtml 后在网上搜到了解决方案,在此分享以供各位遇到问题的同好参考:在ff的地址栏中输入“abo ...

  8. 采用httpclient提交数据到服务器

    1)Get提交数据 效果演示:

  9. x86汇编指令详解

    80x86指令系统 80x86指令系统,指令按功能可分为以下七个部分. (1) 数据传送指令. (2) 算术运算指令. (3) 逻辑运算指令. (4) 串操作指令. (5) 控制转移指令. (6) 处 ...

  10. 微信公众平台开发接口PHP SDK完整版

    <?php /* 方倍工作室 http://www.fangbei.org/ CopyRight 2015 All Rights Reserved */ define("TOKEN&q ...