微软2016校招4月在线笔试——第一题 Font Size
来源:互联网 发布:ubuntu 16.04合理分区 编辑:程序博客网 时间:2024/06/06 13:23
http://hihocoder.com/problemset/problem/1288
↑↑↑ 题目原址。
- 样例输入
21 10 4 3102 10 4 310 10
- 样例输出
32
描述
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.
我的代码:
#include <iostream>using namespace std;int main(){int TASKS, N, P, H, W, S;cin >> TASKS;while (TASKS--){cin >> N >> P >> W >> H;int* ai = new int [N];for (int i = 0; i < N; i++){cin >> ai[i];}S = 1;bool can = true;while (can){int cansavecols = W/S;int cansaverows = H/S;if (cansaverows == 0){S--;break;}int needrows = 0;for (int i = 0; i < N; i++){int needrow = ai[i] / cansavecols;if (ai[i] % cansavecols > 0){needrow++;}needrows += needrow;}int needpages = needrows/cansaverows;if (needrows % cansaverows > 0){needpages++;}if (needpages <= P){can = true;S++;}else{S--;can = false;}}cout << S << endl;}return 0;}
抛砖引玉,希望有更好解法的朋友不吝赐教~~
- 微软2016校招4月在线笔试——第一题 Font Size
- 微软2016校园招聘4月在线笔试:Font Size
- 微软2016年4月实习生笔试第一题-font size题解
- 微软2016校招4月在线笔试——第二题 403Forbidden
- 【hihocoder】Font Size(微软2016.4校招笔试题)
- 微软2016校园招聘4月在线笔试1-Font Size
- hihocoder 1288:Font Size--微软2016校园招聘4月在线笔试
- 微软2016校园招聘4月在线笔试 hihocoder 1288 Font Size (模拟)
- Font Size(微软2016校园招聘4月在线笔试)
- 2016年微软在线笔试题之Font Size
- 微软2016实习生笔试--第一题Font Size
- 微软笔试 Font Size
- 微软笔试题1:Font Size
- [2016.4][微软笔试]Font Size
- 微软苏州校招1月3日在线编程题1——constellations
- 微软苏州校招1月3日在线编程题2——Disk Storage
- 微软2016校园招聘4月在线笔试题
- 【hihocoder】1237 : Farthest Point ->微软2016校招在线笔试题
- 55. Jump Game
- widgets之progressBar
- forward 和redirect用法区别
- 致我终将逝去的青春
- Devstack 初始安装没有neutron组件解决办法
- 微软2016校招4月在线笔试——第一题 Font Size
- 关于android studio代码提示的问题
- 每天laravel-20160706|KeyForgotten
- Android学习笔记----解决“com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536”问题
- activiti自定义流程之Spring整合activiti-modeler5.16实例(七):任务列表展示
- C#点击按钮后其他按钮排列类似导航菜单
- GPG入门
- 排序
- java中去掉html标签