Its width is W and height is H. As a result, if the font size of characters is S then it can only sh

来源:互联网 发布:cardboard软件怎么使用 编辑:程序博客网 时间:2024/06/06 07:09
描述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.样例输入21 10 4 3102 10 4 310 10样例输出32

读了半天意思就是:(百度翻译)

史提芬喜欢在他的手机上看书。这本书他读了由N个段落,每个段落包含AI角色。
史提芬想让角色更容易阅读,所以他决定增加字体大小。但是史提芬的手机屏幕的大小是有限的。它的宽度W和高度H作为一个结果,如果字体大小的就只能显示⌊W / S⌋字符线和⌊H/S⌋线在页。(⌊X⌋是最大的整数不超过x)
所以这里的问题是,如果史提芬想要控制的页面数量不超过磷,什么是最大的字体大小,他可以设置?请注意,段落必须以一个新的行开始,段落之间没有空行。
输入
输入可以包含多个测试用例。
第一行是一个整数任务,代表测试用例的数量。
对于每一个测试案例,第一行包含四个整数N、P、W和H,如上所述。
第二行包含N个整数A1、A2,…一,说明每一段文字的数量。


如果一次只输入一个用例:

import java.util.Scanner;public class Main {public static void main(String[] args) {// TODO Auto-generated method stubScanner  scanner = new Scanner(System.in);int n = scanner.nextInt();int p = scanner.nextInt();int w = scanner.nextInt();int h = scanner.nextInt();int[] a=new int[n];int s=0;int sum=0;for(int i=0;i<n;i++){a[i]=scanner.nextInt();sum+=a[i];}          for( s=0;s<100;s++){          if( (sum*(s*s)/(h*w))<=p ){                  }          else          break;          }System.out.println(s-1);}}//输入://2 10 4 3 //10 10//输出://2  
如果一次输入多个用例:

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner  scanner = new Scanner(System.in);int t = scanner.nextInt();////t表示用例数目int[] n=new int[t];int[] p=new int[t];int[] w=new int[t];int[] h=new int[t];/////这四个变量都用数组存储int[] sum=new int[t];int[]  s = new int[t];int[][] a=new int[10000][10000];for(int i=0;i<t;i++){n[i]=scanner.nextInt();p[i]=scanner.nextInt();w[i]=scanner.nextInt();h[i]=scanner.nextInt();for(int j=0;j<n[i];j++){a[i][j]=scanner.nextInt();sum[i]+=a[i][j];}}for(int k=0;k<t;k++){        for( s[k]=0;s[k]<100;s[k]++){        if (sum[k]*(s[k]*s[k])/(h[k]*w[k])<=p[k]){              }        else        break;        }        System.out.println(s[k]-1);}}}//输入://2//1 10 4 3//10//2 10 4 3 //10 10//输出://3//2
在eclipse上可以,在hihocode上提示WA,我也是醉了,,,


0 0
原创粉丝点击