HDOJ:1058

第一种思路:

对于四个因数:2,3,5,7;首先定义a[original]=1,m=n=x=y=1=original;然后再分别用a[m],a[n],a[x],a[y],来表示2,,3,5,7的个数再比较a[m]乘以2,a[n]乘以3,a[x]乘以5,a[y]乘以7的大小;如果小的那个是a[x],则x++,并将此数值有a[++original]记录下来,再进行比较四者的大小,不断重复直到original==5843;

第一种思路的代码(AC了,要注意输出的格式,我在这里错了4次):

#include <iostream>
#include <algorithm>
#define Max  5844
using namespace std;
long long int a[Max];

void hanshu()
{
	int orginal=1,m=1,n=1,x=1,y=1;
	a[orginal]=1;
	long long int temp,temp1,temp2;
	temp=a[orginal];
	while(orginal!=5843)
	{
		temp1=min(a[n]*2,a[m]*3);
		temp2=min(a[x]*5,a[y]*7);
		temp=min(temp1,temp2);
		if(temp==a[n]*2) n++;
		else if(temp==a[m]*3) m++;
		else if(temp==a[x]*5) x++;
		else if(temp==a[y]*7) y++;
		if(temp!=a[orginal])
			a[++orginal]=temp;
	}
	
	
}

int main(void)
{
	freopen("in.txt","r",stdin);
	hanshu();
	int n;
	while(cin>>n&&n)
	{
		if(n%10==1&&n%100!=11)
			cout<<"The "<<n<<"st humble number is "<<a[n]<<"."<<endl;
		else if(n%10==2&&n%100!=12)
			cout<<"The "<<n<<"nd humble number is "<<a[n]<<"."<<endl;
		else if(n%10==3&&n%100!=13)
			cout<<"The "<<n<<"rd humble number is "<<a[n]<<"."<<endl;
		else
			cout<<"The "<<n<<"th humble number is "<<a[n]<<"."<<endl;
	}
	
	fclose(stdin);
	return 0;
}

  

 

转载于:https://www.cnblogs.com/phaLQ/p/9370670.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值