2016 the first question of Microsoft machine question--fontsize

Source: Internet
Author: User

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

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.