HihoCoder
来源:互联网 发布:淘宝装修代码怎么使用 编辑:程序博客网 时间:2024/06/06 04:55
- 样例输入
21 10 4 3102 10 4 310 10
- 样例输出
32
解题思路:给出行宽和列高,那么字体的大小最大肯定不会超过他们俩的最小值,即一页最少一个字。
那么直接暴力求解,从最大字号开始遍历,找到符合的字体。
先算出宽里能有几个字体,然后用每段的字数对其取余判断是不是要空行,总页数*列长等于总单位行数,判断总段数需要的单位
列长是不是在上面总和的范围内,如果小于的话说明该字体可以符合要求。
贴代码:
#include<stdio.h>int miwh(int a,int b){return a<b?a:b;}int main(){int n,p,w,h,a[1005];int t,i,j,mi,k;int ans=0;scanf("%d",&t);while(t--){scanf("%d%d%d%d",&n,&p,&w,&h);for(i=0;i<n;i++)scanf("%d",&a[i]);mi = miwh(w,h);//此时,字体最大位mi号,然后开始枚举。for(i=mi;i>=1;i--){ans=0;k = w/i;for(j=0;j<n;j++){ans += a[j]%k ? a[j]/k+1 : a[j]/k;}if(ans <= p*(h/i)){printf("%d\n",i);break;}} }return 0;}
描述
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.
- hihocoder:
- hihoCoder
- Hihocoder
- hihocoder
- hihocoder
- hihocoder
- hihocoder
- hihocoder
- HihoCoder
- HihoCoder
- HihoCoder
- HihoCoder
- HihoCoder
- HihoCoder
- hihoCoder
- HihoCoder
- HihoCoder
- HihoCoder
- XDOJ 1229
- LoginInterceptor
- html 中文竖直显示属性
- isNaN不一定准(Effective JavaScript 编写高质量JavaScript代码的68个有效方法)
- CMake快速上手笔记
- HihoCoder
- 心情
- cocos2dx lua 再谈实现EditBox输入框
- java.util.concurrent.Executors 类
- fatal error C1083: Cannot open include file: 'streambuf': No such file or directory解决方案
- java异常处理的五个关键字
- 多线程 竞态条件与临界区
- Java反射
- linux基础(十三)软件安装rpm和yum