Title Description: N paragraphs p pages W of section H of the page length an array gives the number of words per paragraph target to find the maximum character size that meets the requirements.
The difficulty: (1) must according to the description of the topic, give the qualified character input scheme;
(2) using the dichotomy method to approximate the maximum selectable character size;
(3) How to use judgment expression to achieve rounding, and select;
Important thought: The most confusing place is the relationship between the word Fu and the page, it is necessary to see the hierarchical relationship between them; Use the comparison of pages to produce workable results.
1 Packageshounue;2 ImportJava.util.Scanner;3 Public classFontSize {4 Public Static voidMain (string[] args) {5Scanner cin =NewScanner (system.in);6 intNumber =cin.nextint ();7 while(Number > 0){8 intn =cin.nextint ();9 intp =cin.nextint ();Ten intW =cin.nextint (); One inth =cin.nextint (); A int[] Array =New int[n]; - for(inti = 0;i < n;i++){ -Array[i] =cin.nextint (); the } - intleft = 1; - intright =Math.min (W, h); - intresult = 0; + while(Left <=Right ) { - intMid = (left + right)/2; + intColumn = w/mid; A introw = h/mid; at intCount = 0; - for(inti = 0;i < n;i++){ -Count + = ((array[i]%column) = = 0? (array[i]/column): (Array[i]/column + 1)); - } - intpage = ((count%row) = = 0? (Count/row): (Count/row + 1)); - if(Page <=p) { inresult =mid; -left = mid + 1; to}Else { +right = Mid-1; - } the } * System.out.println (result); $number--;Panax Notoginseng } - } the +}
2016 the first question of Microsoft machine question--fontsize