Describe
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 is limited. Its width is W and height are H. As a result, if the font size of characters is S and it can only be 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 the start in a new line and there are no empty line between paragraphs.
Input
Input may contain multiple test cases.
The first line was 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, ... A, 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-to-control the number of pages no more than P.
Output
For each testcase, output a line with an integer Ans, indicating the maximum font size Steven can set.
I'm a little trickery this question. Not very clear how others do, I am using estimates to do, first of all do not write full this special case assignment, after all, exactly a paragraph is full of small probability events, so as to reduce the time complexity of the operation, and then make adjustments, when the boundary, that is, the state changes is the critical point, the following is my code:
#include <iostream>#include<math.h>using namespacestd;intInterintAintb) { if(a%b==0){ returnA/b; }Else{ returna/b+1; }}BOOLPanintUintWintHintA[],intNintP) { intW = w/u; intH = h/u; intt =0; intK = p*h; for(intI=0; i<n;i++) {T+=Inter (A[I],W); if(t>k) { return false; } } return true;}intMain () {intTask; CIN>>Task; intAn[task]; for(intj =0; j<task;j++){ intn,p,w,h; CIN>>N>>P>>W>>H; intA[n]; intS =0; for(inti =0; i<n;i++) {cin>>A[i]; S+=A[i]; } S= (p*h*w)/S; S=sqrt (S); intFlag1 =0; if(Pan (s,w,h,a,n,p)) {Flag1--; while(flag1!=0){ if(Pan (s,w,h,a,n,p)) {S++; }Else{Flag1++; S--; } } }Else{Flag1++; while(flag1!=0){ if(Pan (s,w,h,a,n,p)) {Flag1--; }Else{S--; }}} An[j]=R; } for(intj =0; j<task;j++) {cout<< an[j]<<Endl; }}
Hihocoer Front Size