• hdu 1058 Humble Numbers


    我认为这题更像一道数学题,找规律的,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... 就是要找到这些数之间的规律,a[i]=max(a[s1]*2,max(a[s2]*3,max(a[s3]*5,a[s4]*7)));就是输出格式有点麻烦。

    代码:

     1 #include<stdio.h>
    2 #include<stdlib.h>
    3 #include<string.h>
    4 #include<iostream>
    5 using namespace std;
    6 int min(int x,int y)
    7 {
    8 return x>y?y:x;
    9 }
    10 int main()
    11 {
    12 int n,s1,s2,s3,s4;
    13 int a[5900];
    14 a[1]=1;
    15 s1=s2=s3=s4=1;
    16 for(int i=2;i<=5842;i++)
    17 {
    18 a[i]=min(a[s1]*2,min(a[s2]*3,min(a[s3]*5,a[s4]*7)));
    19 if(a[i]==a[s1]*2)
    20 s1++;
    21 if(a[i]==a[s2]*3)
    22 s2++;
    23 if(a[i]==a[s3]*5)
    24 s3++;
    25 if(a[i]==a[s4]*7)
    26 s4++;
    27 }
    28 while(scanf("%d",&n),n)
    29 {
    30 if(n%10==1&&(n%100)!=11)
    31 printf("The %dst humble number is %d.\n",n,a[n]);
    32 else if(n%10==2&&(n%100)!=12)
    33 printf("The %dnd humble number is %d.\n",n,a[n]);
    34 else if(n%10==3&&(n%100)!=13)
    35 printf("The %drd humble number is %d.\n",n,a[n]);
    36 else
    37 printf("The %dth humble number is %d.\n",n,a[n]);
    38 }
    39 return 0;
    40 }


     

  • 相关阅读:
    48. Rotate Image
    47. Permutations II
    46. Permutations
    45. Jump Game II
    44. Wildcard Matching
    43. Multiply Strings
    42. Trapping Rain Water
    Python_匿名函数
    Python_内置函数之map()
    Python_面向对象_单例模式
  • 原文地址:https://www.cnblogs.com/misty1/p/2269665.html
Copyright © 2020-2023  润新知