zoukankan      html  css  js  c++  java
  • HDU 1058 Humble Numbers

    点我看题目

    题意 : 定义 Humble Numbers为因子中除2,3,5,7外没有别的因子了(当然因子1不包括在这里边),然后给你一个数,让你求出第n个 Humble Numbers是什么。

    思路 :这个主要是求 Humble Numbers麻烦点,你要一点点的往上乘,因为反正这些数都是只由2 3 5 7相乘而成,你就从头开始往上乘2,3,5,7就行了。。。。其实我一点没看出来这个和DP什么关系。。。。

    ////HDU 1025
    //
    //#include <iostream>
    //#include <stdio.h>
    //#include <string.h>
    //
    //using namespace std;
    //
    //int dp[505000] ;
    //int B[505000] ;
    //
    //int main()
    //{
    //    int n ;
    //    int casee = 1 ;
    //    while(~scanf("%d",&n))
    //    {
    //        int a,b ;
    //        for(int i = 0 ; i < n ; i++)
    //        {
    //            scanf("%d %d",&a,&b) ;
    //            dp[a] = b ;//这样就相当于去找dp这个数组的最长上升子序列了
    //        }
    //        int len = 1 ;
    //        B[1] = dp[1] ;
    //        for(int i = 2 ; i <= n ; i++)//这里掉了等号WA到死啊
    //        {
    //            int low = 1 , high = len ;
    //            while(low <= high)
    //            {
    //                int mid = (low+high) >> 1 ;
    //                if(B[mid] < dp[i]) low = mid+1 ;
    //                else high = mid - 1 ;
    //            }
    //            B[low] = dp[i] ;
    //            if(low > len) len++ ;
    //        }
    //        printf("Case %d:
    ",casee++) ;
    //        if(len == 1)
    //            printf("My king, at most 1 road can be built.
    
    ") ;
    //        else printf("My king, at most %d roads can be built.
    
    ",len) ;
    //    }
    //    return 0;
    //}
    //
    //HDU 1058
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    
    using namespace std ;
    
    int humble[5843] ;
    
    int main()
    {
        int n ;
        int a2, a3,a5,a7 ;
        a2 = a3 = a5 = a7 = 1 ;
        int cnt2,cnt3,cnt5,cnt7 ;
        humble[1] = 1 ;
        for(int i = 2 ; i <= 5842 ; i++)
        {
            cnt2 = humble[a2] * 2 ;cnt3 = humble[a3] * 3 ;
            cnt5 = humble[a5] * 5 ;cnt7 = humble[a7] * 7 ;
            humble[i] = min(min(cnt2,cnt3),min(cnt5,cnt7)) ;
            if(humble[i] == cnt2) a2++ ;
            if(humble[i] == cnt3) a3++ ;
            if(humble[i] == cnt5) a5++ ;
            if(humble[i] == cnt7) a7++ ;
        }
        while(~scanf("%d",&n) && n)
        {
            if(n%10 == 1 && n % 100 != 11)
            printf("The %dst humble number is %d.
    ",n,humble[n]) ;
            else if(n%10 == 2 && n%100 != 12)
            printf("The %dnd humble number is %d.
    ",n,humble[n]) ;
            else if(n%10 == 3 && n%100 != 13)
            printf("The %drd humble number is %d.
    ",n,humble[n]) ;
            else
            printf("The %dth humble number is %d.
    ",n,humble[n]) ;
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    addEventListener
    mac截屏
    SVG Use(转)
    关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related(转)
    promise
    apt-get update 出现E: Could not get lock /var/lib/apt/lists/lock问题的解决
    js设计模式——6.模板方法模式与职责链模式
    js设计模式——5.状态模式
    js设计模式——4.迭代器模式
    js实现超简单sku组合算法
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3570048.html
Copyright © 2011-2022 走看看