zoukankan      html  css  js  c++  java
  • 数位DP POJ3208 Apocalypse Someday

    Apocalypse Someday
    Time Limit: 1000MS   Memory Limit: 131072K
    Total Submissions: 1870   Accepted: 902

    Description

    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.

    Input

    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.

    Output

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

    Sample Input

    3
    2
    3
    187

    Sample Output

    1666
    2666
    66666

    Source

    POJ Monthly--2007.03.04, Ikki, adapted from TCHS SRM 2 ApocalypseSomeday
     
     
     
    我不明白我为什么要写这个题,好难……
    lyd的题解 OTZ
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 int t,n,m,k;
     7 long long f[21][4];
     8 void work(){
     9     f[0][0]=1;
    10     for(int i=0;i<20;i++){
    11         for(int j=0;j<3;j++){
    12             f[i+1][j+1]+=f[i][j];
    13             f[i+1][0]+=f[i][j]*9;
    14         }
    15         f[i+1][3]+=f[i][3]*10;
    16     }
    17 }
    18 int main(){
    19     work();
    20     scanf("%d",&t);
    21     while(t){
    22         t--;
    23         scanf("%d",&n);
    24         for(m=3;f[m][3]<n;m++);
    25         k=0;
    26         for(int i=m;i;i--){
    27             for(int j=0;j<=9;j++){
    28                 long long tmp=f[i-1][3];
    29                 if(k==3||j==6)
    30                     for(int p=max(0,3-k-(j==6));p<3;p++)
    31                         tmp+=f[i-1][p];
    32                 if(tmp<n)  n-=tmp;
    33                 else{
    34                     if(k<3&&j==6) k++;
    35                     if(k<3&&j!=6) k=0;
    36                     printf("%d",j);
    37                     break;
    38                 }
    39             }
    40         }
    41         printf("
    ");
    42     }
    43     return 0;
    44 }
     
  • 相关阅读:
    SDNU 1123.Encoding
    SDNU 1120.ISBN号码
    SDNU 1119.Intelligent IME(水题)
    SDNU 1115.谁拿了最多奖学金(水题)
    解决Docker运行命令时提示"Got permission denied while trying to connect to the Docker daemon socket"类情况
    jupyter notebook修改默认浏览器
    CentOS切换用户命令su or su+username
    图像内插,双线性插值等
    python求最大公约数和最小公倍数
    Python split()方法
  • 原文地址:https://www.cnblogs.com/zwube/p/7108023.html
Copyright © 2011-2022 走看看