Hihocoer Front Size

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.