【GoogleCodeJam Qualification Round 2016】Problem A. Counting Sheep

Problem here

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

5
0
1
2
11
1692

output

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

Solution

很紅很暴力
注:1844674407370955161是long long 的最大值
正解在這裡

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include "memory.h"
using namespace std;

ifstream fin("A-large.in"); //ifstream fin("A-small-attempt0.in");
ofstream fout("A-large.out");//ofstream fout("A-small-attempt0.out");

bool check[10];

int slove(int input){
    for(unsigned long long i = 1; i <= 1844674407370955161; i++){
        stringstream ss;
        unsigned long long n;
        n = input * i;
        string str;
        ss << n;
        ss >> str;
        for(int j = 0; j < str.length(); j++){
            switch(str[j]){
                case '0':
                    check[0] = true;
                    break;
                case '1':
                    check[1] = true;
                    break;
                case '2':
                    check[2] = true;
                    break;
                case '3':
                    check[3] = true;
                    break;
                case '4':
                    check[4] = true;
                    break;
                case '5':
                    check[5] = true;
                    break;
                case '6':
                    check[6] = true;
                    break;
                case '7':
                    check[7] = true;
                    break;
                case '8':
                    check[8] = true;
                    break;
                case '9':
                    check[9] = true;
                    break;

            }
        }
        bool pass = true;
        for(int j = 0; j < sizeof(check); j++){
            if(check[j] == false){
                pass = false;
            }
        }
        if(pass){
            return n;
        }else{
            continue;
        }
    }
    return -1;
}

int main(){

    int t;
    while(fin >> t){
        for(int i = 1; i <= t; i++){
            int input;
            fin >> input;
            memset(check, false, sizeof(check));
            fout << "Case #" << i << ": ";
            if(input <= 0){
                fout << "INSOMNIA" << endl;
            }else{
                fout << slove(input) << endl;
            }
        }
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值