微软2016校园招聘4月在线笔试:Font Size
2016-05-04 16:18
489 查看
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
//#include "stdafx.h"
#include<iostream>
#include<cstring>
#include<string>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main()
{
// freopen("in.txt", "r", stdin);
int t;
cin >> t;
int N, P, W, H;
while (t--){
cin >> N >> P >> W >> H;
int sum = 0;
int *a = new int
;
for (int i = 0; i < N; i++){
cin >> a[i];
sum += a[i];
}
int m = min(W, H);
int sum_l=0;
for (int i = m; i >= 1; i--){
for (int j = 0;j < N;j++){
sum_l += a[j] % (W / i);
}
sum_l = sum + sum_l;
if (((W / i)*(H / i)*P) >= sum_l){
cout << i << endl;
sum_l = 0;
break;
}
sum_l = 0;
}
}
//freopen("CON", "r", stdin);
//system("pause");
return 0;
}
相关文章推荐
- 百度2014校园招聘笔试题 ——深度学习算法研发工程师.
- 企鹅2015校招笔试之(一)抽奖算法思路实现
- 企鹅2015校招笔试之(二)整形长度算法思路实现
- 24岁的自我审视
- 2015年去哪网校园招聘笔试题
- 阿里巴巴2010校园招聘技术类笔试试题
- 笔试与面试集锦
- 计算机面试题目以及心得
- 2015网龙笔试题
- 百度2015校园招聘 面试算法题
- 阿里巴巴2015校园招聘面试汇总
- 2015去哪儿网校园招聘笔试题:寻找字符串的差异
- 百度2015校园招聘笔试、面试汇总
- 【搜狗笔试题】给定一个数组a[N],我们希望构造数组b[N]
- 【LeetCode刷题】旋转数组的查找 Search in Rotated Sorted Array
- 爱奇艺2015校园招聘产品笔试题
- 应聘互联网技术类工作的简历该怎么写,一点建议
- 去哪儿网2015校园招聘前端笔试题
- 百度2015校园招聘一、二、三面面试经历(软件研发岗)