传送:http://codeforces.com/gym/101612

题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的k的答案。

注意这k步不一定是连续的。

分析:

对于每个数,可以有两种操作:

1. 先将有倍数的数变成它们的最大倍数,而且按照出现次数比较少的先变。

2. 将所有数都变成lcm,而且按照出现次数比较少的先变。

数组f[i]代表,操作i次的最小种类数。对于每一次操作,取min。

 #include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+;
const int inf=1e6+;
map<int,int> mp;
vector<int> v[];
int f[maxn];
int main(){
freopen("equal.in","r",stdin);
freopen("equal.out","w",stdout);
int n,xx; cin >> n;
mp.clear();
for (int i=;i<n;i++){
cin >> xx;
mp[xx]++;
}
int num=mp.size();
v[].clear(); v[].clear();
for (auto it:mp){
int i=it.first;
v[].push_back(it.second);
for (int j=i+i;j<inf;j+=i)
if (mp.count(j)){
v[].push_back(it.second); break;
}
}
memset(f,0x7f,sizeof(f));
f[]=num;
//变成该数的倍数(在数列中出现)
sort(v[].begin(),v[].end());
int len=v[].size(),sum=;
for (int i=;i<len;i++){
sum+=v[][i];
f[sum]=min(f[sum],num-(i+));
}
//变成最小公倍数
sort(v[].begin(),v[].end());
len=v[].size(); sum=;
for (int i=;i<len;i++){
sum+=v[][i];
f[sum]=min(f[sum],num-i);
}
cout << f[];
for (int i=;i<=n;i++){
if (i) f[i]=min(f[i],f[i-]);
cout << " " << f[i];
}
cout << endl;
return ;
}

Codeforces gym101612 E.Equal Numbers(贪心)的更多相关文章

  1. Codeforces.GYM101612E.Equal Numbers(贪心)

    题目链接 \(Description\) 给定\(n\)个数,每次可以将任意一个数乘上任意一个正整数. 求\(k\)次操作后,数列中数的种类最少可以是多少.对每个\(0\leq k\leq n\)输出 ...

  2. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  3. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  4. Codeforces 1065C Make It Equal (差分+贪心)

    题意:n个塔,第i个塔由$h_i$个cube组成,每次可以切去某高度h以上的最多k个cube,问你最少切多少次,可以让所有塔高度相等 k>=n, n<=2e5 思路:差分统计每个高度i有的 ...

  5. Codeforces Round #479 (Div. 3) C. Less or Equal (排序,贪心)

    题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排 ...

  6. Codeforces 798D Mike and distribution - 贪心

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

  7. Codeforces H. Maximal GCD(贪心)

    题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces 1119E Pavel and Triangles (贪心)

    Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal t ...

  9. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

随机推荐

  1. leetcode406

    public class Solution { public int[,] ReconstructQueue(int[,] people) { ) { return new int[,] { }; } ...

  2. <记录>TP5 关联模型使用(嵌套关联、动态排序以及隐藏字段)

    在数据库设计中,常常会有如下这种关联模型,分类表中一条分类对应多个商品表中的商品 如果要获得分类表中每条分类 以及 对应的商品的信息,则需要先查询分类表中的数据,然后根据结果遍历查询商品表,最后把数据 ...

  3. 深度学习原理与框架-猫狗图像识别-卷积神经网络(代码) 1.cv2.resize(图片压缩) 2..get_shape()[1:4].num_elements(获得最后三维度之和) 3.saver.save(训练参数的保存) 4.tf.train.import_meta_graph(加载模型结构) 5.saver.restore(训练参数载入)

    1.cv2.resize(image, (image_size, image_size), 0, 0, cv2.INTER_LINEAR) 参数说明:image表示输入图片,image_size表示变 ...

  4. fastJson注解@JSONField使用的一个实例

    1.实体类 package jsonArrayjsonObject.cn; import java.io.Serializable; import java.util.Date; import com ...

  5. linux下启动tomcat服务

     Linux下tomcat服务的启动.关闭与错误跟踪,使用PuTTy远程连接到服务器以后,通常通过以下几种方式启动关闭tomcat服务:切换到tomcat主目录下的bin目录(cd usr/local ...

  6. GDI+_入门教程【一】

    GDI For VisualBasic6.0 [一]文件下载:GDI+ For VB6[一] 简单绘图实例演示百度网盘 1 '以下为作者[vIsiaswx]的教程 '(该教程发布的原地址已无法访问,此 ...

  7. 数据库类型空间效率探索(五)- decimal/float/double/varchar

    以下测试为userinfo增加一列,列类型分别为decimal.float.double.varchar.由于innodb不支持optimize,所以每次测试,都会删除表test.userinfo,重 ...

  8. Linux进程的原理及与信号的联系

    第1节 程序.进程.守护进程.僵尸进程的区别 程序.进程.守护进程.僵尸进程: 程序:c/php/java,代码文件,静态的,放在磁盘里的数据. 进程:正在内存中运行的程序,进程是动态的,会申请和使用 ...

  9. Django的rest_framework的权限组件和频率组件源码分析

    前言: Django的rest_framework一共有三大组件,分别为认证组件:perform_authentication,权限组件:check_permissions,频率组件:check_th ...

  10. [leetcode]72. Edit Distance 最少编辑步数

    Given two words word1 and word2, find the minimum number of operations required to convert word1 to ...