Google Code Jam Contest-2016-April-09th

Source: Internet
Author: User

One, qualifying tournament:

1,

problem A. Counting sheepconfused? Read the quick-Start Guide. Small input7points you have solved ThisInputSet. Large input8points you have already tried ThisInputSet. (judged at the end of the contest.) Problembleatrix Trotter the sheep have devised a strategy that helps her fall asleep faster. First, she picks a number N. Then she starts naming N,2Xn,3Xn, and so on. Whenever she names a number, she thinks about all of the digitsinchThat number. She keeps track of which digits (0,1,2,3,4,5,6,7,8, and9) She has seen at least once so far asPart of any number she has named. Once She has seen all of the ten digits at least Once, she'll fall asleep. Bleatrix must start with N and must always name (I+1) xn directly after ixn. For example, suppose that Bleatrix picks N =1692. She would count asfollows:n=1692. Now she has seen the digits1,2,6, and9. 2N=3384. Now she has seen the digits1,2,3,4,6,8, and9. 3N= the. Now she had seen all ten digits, and falls asleep. what isThe last number, the she'll name before falling asleep?If She'll count forever, print INSOMNIA instead. Inputthe first line of the input gives the number of test cases, T. t test cases follow. Each consists of one line with a single integer N, the number Bleatrix has chosen. Outputfor each test Case, output one line containing case #x: Y,whereX isThe test CaseNumber (starting from 1) and Y isThe last number that Bleatrix would name before falling asleep, according to the rules describedinchThe statement. Limits1≤t≤ -. Small DataSet0≤n≤ $. Large DataSet0≤n≤106. Sampleinput Output5012 One1692Case #1: Insomniacase #2:TenCase #3: -Case #4: theCase #5: theIn case #1, since2X0=0,3X0=0, and so on, Bleatrix'll never see any digit other than0, and so she'll count forever and never fall asleep. Poor sheep!In case #2, Bleatrix would name1,2,3,4,5,6,7,8,9,Ten. The0'll is the last digit needed, and so she'll fall asleep afterTen. in case #3, Bleatrix would name2,4,6... and so on. She won't see the digit9 inchAny number until -At which point she'll fall asleep. By, she would have already seen the digits0,1,2,3,4,5,6,7, and8, which'll has appeared forThe first timeinchThe numbersTen,Ten,2, -,4, -,6, -, and8, respectively. in case #4, Bleatrix would name One, A, -, -, -, the, the, the, About, theAnd then fall asleep. Case #5  isThe one describedinchThe problem statement. Note that it would only show upinchThe Large dataset, and notinchThe Small dataset.
View Code

Answer:

ImportJava.util.*;ImportJava.io.*; Public classMain { Public Static voidMain (string[] args)throwsfilenotfoundexception {fileinputstream fis=NewFileInputStream ("A-large.in"); PrintStream out=NewPrintStream (NewFileOutputStream ("A-large.out"));    System.setin (FIS);    System.setout (out); Scanner in=NewScanner (NewBufferedReader (NewInputStreamReader (system.in)); intt = In.nextint ();//Scanner have functions to read ints, longs, strings, chars, etc.     for(inti = 1; I <= t; ++i) {intn =In.nextint (); HashSet<Integer> hash =NewHashSet (); if(n = = 0) {System.out.println ("Case #" + i + ": INSOMNIA"); } Else {            intK = 1;  while(Hash.size ()! = 10) {Hash.addall (Getnum (n*k)); K++;//System.out.println (hash.tostring ());} System.out.println ("Case #" + i + ":" + N * (k-1)); }    }  }  Private StaticHashset<integer> Getnum (intN) {HashSet<Integer> hash =NewHashSet ();  while(n! = 0) {Hash.add (n% 10); N= N/10; }      returnHash; }}
View Code

Google Code Jam Contest-2016-April-09th

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.