Codeforces 632D Longest Subsequence 水题

文章目录

题意

给 一 个 序 列 , 求 一 个 元 素 个 数 最 多 的 子 集 , 里 面 所 有 数 字 的 最 小 公 倍 数 不 超 过 m . 按 照 下 标 从 小 到 大 的 顺 序 输 出 任 何 一 个 . 给一个序列,求一个元素个数最多的子集,里面所有数字的最小公倍数不超过m.\newline按照下标从小到大的顺序输出任何一个. ,,m..

题解

水题.不会做真是锅大了.
首先一看数据范围, 1 0 9 10^9 109.哎呦我去,怎么做.
m ≤ 1 0 6 . m\leq10^6. m106.
哎呦我去,辣鸡.
首先把小于或者等于 m m m的数字和它的下标保存下来.
我们定义 c n t [ i ] cnt[i] cnt[i] a a a数组里 i i i的约数出现的个数.
我们可以轻松地把 c n t cnt cnt数组在调和级数复杂度内处理出来.
接下来取出来的最大值就是 c n t cnt cnt数组的最大值,此时取出来的所有数字的最小公倍数就是最大值的下标.
最后扫一遍把所有能整除最大值下标的数字下标输出即可.
谢谢大家.

#include<bits/stdc++.h> //Ithea Myse Valgulious
using namespace std;
const int yuzu=1e6;
typedef int fuko[yuzu|10];
fuko a,b,cnt;
int main(){
    
    
int n,m,i,x,top=0,j;
for (read(n),read(m),i=1;i<=n;++i) 
  if ((x=read())<=m) ++cnt[a[++top]=x],b[top]=i;
for (n=top,i=m;i;--i)
  for (j=i<<1;j<=m;j+=i) cnt[j]+=cnt[i];
int llx=-1,p;
for (i=1;i<=m;++i) if (cnt[i]>llx) llx=cnt[i],p=i;
write(p),p32,write(llx),pl;
for (i=1;i<=n;++i) if (p%a[i]==0) write(b[i]),p32;
}

猜你喜欢

转载自blog.csdn.net/qq_31908675/article/details/83658500