(HDU) 1058--humble Numbers (ugly number)

Source: Internet
Author: User

Title Link: http://vjudge.net/problem/HDU-1058

This problem is a bit difficult, I wrote for a long while still tle, referring to other people's blog.

http://blog.csdn.net/pythonfx/article/details/7292835

http://blog.csdn.net/x_iya/article/details/8774087

The second person's blog uses DP, which is not suitable for the basic problem.

1#include <stdio.h>2 intf[5843],n;3 inti,j,k,l;4 5 intMinintAintBintCintd) {6     intmin=A;7     if(b<min) min=b;8     if(c<min) min=C;9     if(d<min) min=D;Ten  One     if(a==min) i++; A     if(b==min) J + +; -     if(c==min) k++; -     if(d==min) l++; the  -     returnmin; - } -  + intMain () { -I=j=k=l=1; +f[1]=1; A      for(intt=2; t<=5842; t++) atF[t]=min (2*f[i],3*F[J],5*f[k],7*f[l]); -  -      while(SCANF ("%d", &n) &&n!=0){ -         if(n%Ten==1&&n% -!= One) -printf"The %dst humble number is%d.\n", N,f[n]); -         Else if(n%Ten==2&&n% -!= A) inprintf"The %dnd humble number is%d.\n", N,f[n]); -         Else if(n%Ten==3&&n% -!= -) toprintf"The %DRD humble number is%d.\n", N,f[n]); +         Else -printf"The %dth humble number is%d.\n", N,f[n]); the     } *     return 0; $}
View Code
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Long Longf[6000];7 intMain ()8 {9     intN;Ten     intprime[4]={2,3,5,7}; Onef[1]=1; A      for(intI=2; i<=5842; i++) -     { -f[i]=2000000001; the          for(intj=0;j<4; j + +) -         { -              for(intk=i-1;k>0; k--) -             { +                 if(f[k]*prime[j]<=f[i-1]) -                      Break; +                 if(F[k]*prime[j]<f[i])//????????? Af[i]=f[k]*Prime[j]; at             } -         } -     } -      while(SCANF ("%d",&N), N) -     { -         if(n%Ten==1&&n% -!= One) inprintf"The %dst humble number is%lld.\n", N,f[n]); -         Else if(n%Ten==2&&n% -!= A) toprintf"The %dnd humble number is%lld.\n", N,f[n]); +         Else if(n%Ten==3&&n% -!= -) -printf"The %DRD humble number is%lld.\n", N,f[n]); the         Else *printf"The %dth humble number is%lld.\n", N,f[n]); $     }Panax Notoginseng     return 0; -}
View Code

(HDU) 1058--humble Numbers (ugly number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.