- Panda的烦恼
题解
- 2025-6-9 13:33:10 @
-
鉴于 n 十分小,k 又十分大,而且发现 n*k 的时间也是可以的,于是就想想用普通数组来模拟出优先队列。我用了个 b[i] 来记录第 i 个素数当前乘到了 ans[] 中第几个数(好像是下一个应该乘的数),然后每次要加一个数到 ans[] 中时,对每个素数乘一下它下一个要乘的,取出最小值,判一下重,如果无恙就放到 ans[] 后面即可。
-
这样就保证了 ans[] 数组中的元素是单调递增的,而且不会跳元素。
-
时间复杂度应该就是 n*k
程序
#include <cstdio>
int n,k,cnt;
int a[1005],b[1005],ans[100005];
int main(){
scanf("%d%d",&n,&k);
for (int i=1; i<=n; i++) scanf("%d",&a[i]);
ans[0]=1;
while (cnt<k){
int Min=2147483647,Minx;
for (int i=1; i<=n; i++)
if (ans[b[i]]*a[i]<Min){
Min=ans[b[i]]*a[i];
Minx=i;
}
b[Minx]++;
if (Min!=ans[cnt]) ans[++cnt]=Min;
}
printf("%d",ans[k]);
}
0 comments
No comments so far...
Information
- ID
- 108
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 1
- Accepted
- 1
- Uploaded By