hdu 1058 && 3199 Humble Numbers Hamming Problem

16 篇文章 0 订阅

题目链接   http://acm.hdu.edu.cn/showproblem.php?pid=1058

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3199

两道题差不多  有一道可以直接用容器打表,比较简单,另一道就是用dp  正规方法做的

 

hdu1055

可以dp  不过直接用容器也挺简单

记得排序去重

while循环的范围稍微开大点不然WA

我也不知道为什么

emm

玄学AC

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string>
using namespace std;
#define ll long long int
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
vector<ll>mp;
int main()
{
	std::ios::sync_with_stdio(false);
	int j,n,i;
	mp.clear();
	mp.push_back(0);
	mp.push_back(1);
	j=1;
	while(mp.size()<9843)
	{
		mp.push_back(2*mp[j]);
		mp.push_back(3*mp[j]);
		mp.push_back(5*mp[j]);
		mp.push_back(7*mp[j]);
		j++;
		sort(mp.begin(),mp.end());
		mp.erase(unique(mp.begin(),mp.end()),mp.end());
	}
	
	while(cin>>n&&n)
	{
		if(n%10==1&&n%100!=11)
			cout<<"The "<<n<<"st humble number is ";
		else if(n%10==2&&n%100!=12)
			cout<<"The "<<n<<"nd humble number is ";
		else if(n%10==3&&n%100!=13)
			cout<<"The "<<n<<"rd humble number is ";
		else 
			cout<<"The "<<n<<"th humble number is ";
		cout<<mp[n];
		cout<<"."<<endl;
	}

	return 0;
} 

hdu3199

dp

每次求出最小值救星

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
vector<ll>mp;
int main()
{
    std::ios::sync_with_stdio(false);
    ll p1,p2,p3,i,k1,k2,k3,j;
    while(cin>>p1>>p2>>p3>>i)
    {
        if(p1>p2)swap(p1,p2);
        if(p1>p3) swap(p1,p3);
        if(p2>p3)swap(p2,p3);
        
        mp.clear();
        mp.push_back(1);
        k1=k2=k3=0;
        for(j=1;j<=i;j++)
        {
            ll x=min(p1*mp[k1],min(p2*mp[k2],p3*mp[k3]));
            mp.push_back(x);
            if(x==p1*mp[k1])k1++;
            if(x==p2*mp[k2])k2++;
            if(x==p3*mp[k3])k3++;
            
        }
        cout<<mp[i]<<endl;
    }

    return 0;
} 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值