zoukankan      html  css  js  c++  java
  • HDU 1058

    利用一个数组 a[N] 来保存自己所需要的数据,对于我们要得到a[i] , 那么a[i] 必然是由前i-1个数中的某一个,乘以2,3,5,7中的某个得到的最小值

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 using namespace std;
     5 
     6 #define maxn 5842
     7 int a[maxn+1];
     8 
     9 void get_table()
    10 {
    11     int l1=1 , l2=1 , l3=1 , l4 = 1;
    12     a[1] = 1;
    13     for(int i = 2 ; i<=maxn ; i++){
    14         int n1 = a[l1] * 2;
    15         int n2 = a[l2] * 3;
    16         int n3 = a[l3] * 5;
    17         int n4 = a[l4] * 7;
    18         a[i] = min(min(n1 , n2) , min(n3 , n4));
    19         if(a[i] == n1) l1++;
    20         if(a[i] == n2) l2++;
    21         if(a[i] == n3) l3++;
    22         if(a[i] == n4) l4++;
    23     }
    24 }
    25 
    26 int main()
    27 {
    28     get_table();
    29     int n;
    30     while(~scanf("%d" , &n)){
    31         if(n == 0) break;
    32         if(n % 10 == 1 && n % 100 != 11)
    33             printf("The %dst humble number is %d.
    " , n , a[n]);
    34         else if(n % 10 == 2 && n % 100 != 12)
    35             printf("The %dnd humble number is %d.
    " , n , a[n]);
    36         else if(n % 10 == 3 && n % 100 != 13)
    37             printf("The %drd humble number is %d.
    " , n , a[n]);
    38         else
    39             printf("The %dth humble number is %d.
    " , n , a[n]);
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    SqlLikeAttribute 特性增加 左、右Like实现
    MySql高效分页SQL
    ConcurrentQueue对列的基本使用方式
    第一次
    kubeadm搭建高可用k8s平台(多master)
    prometheus监控
    pyecharts地图中显示地名
    anaconda安装及使用
    Python的pyecharts安装
    安装MY SQL详细步骤
  • 原文地址:https://www.cnblogs.com/CSU3901130321/p/4170683.html
Copyright © 2011-2022 走看看