【GoogleCodeJam2016A】【暴力】Counting Sheep x的倍数从小向大增加直到出现0~9所有数的最小倍增终点
2016-04-10 12:27
417 查看
Counting Sheep
This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-StartGuide to get started.
Small input 7 points | Solve A-small |
Large input 8 points | Solve A-large |
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
INSOMNIAinstead.
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 Bleatrixhas chosen.
Output
For each test case, output one line containingCase #x: y, where
xis
the test case number (starting from 1) and
yis 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 #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.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1010, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int casenum, casei;
void fre()
{
freopen("c://test//input.in", "r", stdin);
freopen("c://test//output.out", "w", stdout);
}
LL ans[1000010];
void table()
{
int aim = (1 << 10) - 1;
for (int X = 1; X <= 1000000; ++X)
{
LL x = X;
int sta = 0;
int step = 0;
while (1)
{
++step;
for (LL y = x; y; y /= 10)sta |= 1 << y % 10;
if (sta == aim)break;
x += X;
}
ans[X] = x;
}
}
int main()
{
//fre();
table();
scanf("%d", &casenum);
for (casei = 1; casei <= casenum; ++casei)
{
int x;
scanf("%d", &x);
if (x == 0)printf("Case #%d: INSOMNIA\n", casei);
else printf("Case #%d: %lld\n", casei, ans[x]);
}
return 0;
}
/*
【题意】 https://codejam.withgoogle.com/codejam/contest/6254486/dashboard 给你一个数x,我们会不停地对x倍增,得到1x,2x,3x,...,nx……
如果在当前所有倍增的数中,已经出现了0~9的所有数,那么我们的倍增就停止。
停止时的数设为y,则我们就要输出y。
【类型】
暴力
【分析】
一个数倍增,总是可以倍增到高位为1,然后各个数字依次出现。
所以我们直接暴力就可以AC啦。
*/
相关文章推荐
- 用fail2ban阻止SSH和VSFTP暴力破解密码
- 2015BJOI day1第三题 糖果candy
- 4495: Least Prime factor 找到最小质因子P的第N小正整数
- HDU 2082
- 暴力枚举法求最大连续和
- HUST-1601 - Shepherd 暴力
- CodeForces 241F Race
- POJ 2965.The Pilots Brothers' refrigerator
- POJ 1753.Flip Game
- POJ 3295.Tautology
- hdu 5533 Dancing Stars on Me
- hdu5532Almost Sorted Array
- 没参加的2015百度之星——数矩形
- poj 3279 Fliptile
- Birthday Cake——直线分割
- Spiral——找规律暴力
- POJ 1166&IOI 1994 The blocks 暴力枚举 解题报告
- hdu 1248
- 20160314 CodeVS 1005 生日礼物,1031 质数环,1049 棋盘染色
- 20160316 Codevs 1018 单词接龙,1166 矩阵取数(60'),1297 硬币,1009 产生数