2013
11-12

# Apocalypse Someday

The number 666 is considered to be the occult “number of the beast” and is a well used number in all major apocalypse themed blockbuster movies. However the number 666 can’t always be used in the script so numbers such as 1666 are used instead. Let us call the numbers containing at least three contiguous sixes beastly numbers. The first few beastly numbers are 666, 1666, 2666, 3666, 4666, 5666…

Given a 1-based index n, your program should return the nth beastly number.

The first line contains the number of test cases T (T ≤ 1,000).

Each of the following T lines contains an integer n (1 ≤ n ≤ 50,000,000) as a test case.

For each test case, your program should output the nth beastly number.

3
2
3
187

1666
2666
66666

/* @author: */
import java.util.Scanner;
public class Main {

static int s[][]=new int[14][4];

static int to[][]=new int[4][10];

static void doit( ) {
int i, j, k;

for( i=0; i< 3; i++ )
for( j=0; j< 10; j++ )
to[i][j] = 0;
to[0][6] = 1;
to[1][6] = 2;
to[2][6] = 3;
for( j=0; j< 10; j++ )
to[3][j] = 3;

s[0][3] = 1;

for( i=1; i< 14; i++ )
for( j=0; j< 4; j++ )
for( k=0; k< 10; k++ )
s[i][j] += s[i-1][to[j][k]];
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int i, j, n, k, t;
long ans;

doit( );
t=sc.nextInt();

while(( t-- )!=0){
n=sc.nextInt();
ans = 0;
k = 0;
for( i=0; i< 14 && s[i][0] < n; i++ )
;
while( (i-- )!=0) {
for( j=0; j< 10 && s[i][to[k][j]] < n; j++ )
n -= s[i][to[k][j]];
ans = ans*10+j;
k = to[k][j];
}
System.out.printf( "%d\n", ans );
}
}
}

1. 题本身没错，但是HDOJ放题目的时候，前面有个题目解释了什么是XXX定律。
这里直接放了这个题目，肯定没几个人明白是干啥