版权声明:欢迎转载,转载请注明出处,如有错误,还望指出,谢谢 博客地址:https://blog.csdn.net/lanyanzhiji123asd https://blog.csdn.net/lanyanzhiji123asd/article/details/87538570
题目链接 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;
}