Google code jam 竞赛 -2016年-04月-09日

一,资格赛:

1,

Problem A. Counting Sheep
Confused? Read the quick-start guide.
Small input
7 points
You have solved this input set.
Large input
8 points
You have already tried this input set. (Judged at the end of the contest.)
Problem

Bleatrix Trotter the sheep has devised a strategy that helps her fall asleep faster. First, she picks a number N. Then she starts naming N, 2 × N, 3 × N, and so on. Whenever she names a number, she thinks about all of the digits in that number. She keeps track of which digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) she has seen at least once so far as part of any number she has named. Once she has seen each of the ten digits at least once, she will fall asleep.

Bleatrix must start with N and must always name (i + 1) × N directly after i × N. For example, suppose that Bleatrix picks N = 1692. She would count as follows:

N = 1692. Now she has seen the digits 1, 2, 6, and 9.
2N = 3384. Now she has seen the digits 1, 2, 3, 4, 6, 8, and 9.
3N = 5076. Now she has seen all ten digits, and falls asleep.
What is the last number that she will name before falling asleep? If she will count forever, print INSOMNIA instead.

Input

The 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.

Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the last number that Bleatrix will name before falling asleep, according to the rules described in the statement.

Limits

1 ≤ T ≤ 100.
Small dataset

0 ≤ N ≤ 200.
Large dataset

0 ≤ N ≤ 106.
Sample

Input 

Output 

5
0
1
2
11
1692

Case #1: INSOMNIA
Case #2: 10
Case #3: 90
Case #4: 110
Case #5: 5076

In Case #1, since 2 × 0 = 0, 3 × 0 = 0, and so on, Bleatrix will never see any digit other than 0, and so she will count forever and never fall asleep. Poor sheep!

In Case #2, Bleatrix will name 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. The 0 will be the last digit needed, and so she will fall asleep after 10.

In Case #3, Bleatrix will name 2, 4, 6... and so on. She will not see the digit 9 in any number until 90, at which point she will fall asleep. By that point, she will have already seen the digits 0, 1, 2, 3, 4, 5, 6, 7, and 8, which will have appeared for the first time in the numbers 10, 10, 2, 30, 4, 50, 6, 70, and 8, respectively.

In Case #4, Bleatrix will name 11, 22, 33, 44, 55, 66, 77, 88, 99, 110 and then fall asleep.

Case #5 is the one described in the problem statement. Note that it would only show up in the Large dataset, and not in the Small dataset.

答案:

import java.util.*;
import java.io.*;
public class Main {
  public static void main(String[] args) throws FileNotFoundException {
    FileInputStream fis = new FileInputStream("A-large.in");
    PrintStream out = new PrintStream(new FileOutputStream("A-large.out"));
    System.setIn(fis);
    System.setOut(out);
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int t = in.nextInt();  // Scanner has functions to read ints, longs, strings, chars, etc.
    for (int i = 1; i <= t; ++i) {
        int n = in.nextInt();
        HashSet<Integer> hash = new HashSet();
        if (n == 0) {
            System.out.println("Case #" + i + ": INSOMNIA");
        } else {
            int k = 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 static HashSet<Integer> getNum (int n) {
      HashSet<Integer> hash = new HashSet();
      while (n != 0) {
          hash.add(n % 10);
          n = n / 10;
      }
      return hash;
  }
}

时间: 2024-09-30 23:58:47

Google code jam 竞赛 -2016年-04月-09日的相关文章

2016年04月29日【EPM-易通元】最新价位公布

2016年04月29日[EPM-易通元]最新价位公布   涨了.涨了.又涨了!   我们的「EPM易通元」天天见涨!太给力了!!   2016.04.29日今天已涨0,01美金,目前已到0.35美金啦!   如果你有1000个易通元,你今天就收益10美金   如果你有10000个易通元,今天就收益100美金   如果你有100000个易通元,你今天就收益1000美金.   恭喜买到「EPM易通元」的朋友们,买到即是赚到!   买入210美金到3500美金 :1美金:6.3人民币兑换,举例买入35

2016年04月30日【EPM-易通元】最新价位公布

涨了.涨了.又涨了! 我们的「EPM易通元」天天见涨!太给力了!! 2016.04.30日今天早晨已涨0.01美金,目前已到0.37美金啦!如果你有1000个易通元,你今天就收益10美金 如果你有10000个易通元,今天就收益100美金 如果你有100000个易通元,你今天就收益1000美金 如果你有1000000个易通元,你今天就收益10000美金. 恭喜买到「EPM易通元」的朋友们,买到即是赚到! 买入210美金到3500美金 :1美金:6.3人民币兑换,举例买入3500美金(人民币2205

2016年04月28日-统一沟通之OCS 2007 R2-公开课-视频

链接:http://pan.baidu.com/s/1sl46yi5 密码:s4gz 2016-04-28-部署-OCS 2007 R2-精讲-视频 培训课件-2010-统一沟通-OCS 2007 R2 前期公开课视频(免费): SFB公开课:TMG/IISARR/Web Application Proxy/发布UC(Lync/SFB)-1 http://dynamic.blog.51cto.com/711418/1760251 SFB公开课:TMG/IISARR/Web Application

2016年04月28日-统一沟通之OCS 2007 R2-公开课-通知

方式:QQ讨论组.(联系人QQ:3313395633) 时间:2016-04-28 20:00-22:00 主题:重温OCS 2007 R2年代(带您回到6年前!) 内容: 您还记得 OCS 2007 R2 吗 ? 你还想知道 OCS 2007 R2 有那些服务器角色吗 ? 你还想知道 如何实现 OCS 2007 R2 内部外部登录吗 ? 你还想知道 OCS 2007 R2 如何实现电话集成吗 ? 本次公开课将带大家回到2010年,本讲师第一次涉足企业与个人培训. 本次公开课将为大家讲解以下图中

谷歌CEO 宣布Google I/O 2016大会将于2016年5月18日Mountain View举办

谷歌CEO Sundar Pichai今日在他的官方Twitter上宣布,Google I/O 2016大会将于2016年5月18日在加州Mountain View拉开帷幕. 这是谷歌一年一度最大的开发者大会.在刚刚过去的2015年,Google I/O大会被评为2015年最受欢迎的开发者大会,位列苹果,微软等各大开发公司大会之首. 你可以通过以下链接订阅Google I/O 2016的新闻已经该大会官方内容. 此外,如果你想体验以下2015年的Google I/O大会,可以观看如下Google

2016年04月MVP开始申请了~[截止时间:1月12日]

51CTO与微软中国合作长期为用户提供申请"微软最有价值专家"的平台希望有兴趣.资历的朋友以及正在朝这个方向努力的朋友能够积极参与只要您想参与我们将为您向微软推荐 微软最有价值专家MVP一年评选4次分别为每年的1月.4月.7月.10月.2016年4月的MVP申请截止时间是2016年1月12日. 申请MVP的午饭请下载2016年4月MVP申请表填好后发送到[email protected].我们会在每次MVP申请开始时把用户提交的申请表格推荐到微软中国相关部门 [注意事项]1.51CTO

Google Code Jam 2014 Round2

Google Code Jam Round2 晚上10点开始的,开始google一直上不去,然后开了个vpn就行了. 说说我的情况吧. P1就是某年noip普及组纪念品分组,贪心. p2是说给你一个排列,然后每次可以交换两个相邻的数,使得最后序列变为先上升后下降的样子.(n<=1000) 一开始题目看错了,以为是交换任意两个,然后愣了半天不会,去写后两题暴力了. (话说我Round1Cp1题目也看错了害的我逗了好久) 后来突然发现是adjacent elements...(<论英语学习的重要性

Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a window separates adjacent cells, and

Google Code Jam 2012 Practice - Store Credit

Problem You receive a credit C at a local store and would like to buy two items. You first walk through the store and create a list L of all available items. From this list you would like to buy two items that add up to the entire value of the credit