题目链接:http://acm.split.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=723
//又是五个小时,一天没吃东西,快虚脱了
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=1e9+2;
int n,m,k,p,q,t;
int a[200010],b[100002];
int st(int x)
{
if(x==1)
return 2;
if(x==2)
return 3;
if(x==3)
return 5;
return 7;
}
void dfs(int y)
{
if(y==5)
return;
ll x;
for(x=st(y); x<=N; x*=st(y))
{
for(int i=m; i; i--)
if(a[i]*x<=N)
a[++m]=a[i]*x;
}
dfs(y+1);
}
int main()
{
scanf("%d",&k);
a[m=1]=1;
dfs(1);
sort(a+1,a+m+1);
while(~scanf("%d",&n))
{
t=a[lower_bound(a+1,a+m+1,n)-a];
printf("%d\n",t);
}
return 0;
}

本文通过一个具体的ACM竞赛题目,展示了使用C++实现的一种高效算法解决方案。文章深入介绍了算法的设计思路,包括深度优先搜索(DFS)的应用以及如何通过排序优化查找过程。适合对算法竞赛感兴趣或希望提高自己算法能力的读者。
144

被折叠的 条评论
为什么被折叠?



