传送: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. BBS(第三天) 如何吧用户上传的图片文件保存到本地

    1. 将用户上传的所有静态文件统一管理 -- settings.py -- MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 2. 服务器会对外公开一下服务器静 ...

  2. 模拟器 Unable to execute simctl install Error 117

    ios 模拟器 Unable to execute '"/usr/bin/xcrun" simctl install  "/Users/tt/PAServer/scrat ...

  3. ArcGIS自定义工具箱-修复损坏的工作空间

    ArcGIS自定义工具箱-修复损坏的工作空间 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:替换数据源的工作空间 用途:针对损坏的数据源,批量进行修复 案例数 ...

  4. uboot1.1.6

    http://blog.csdn.net/lizuobin2/article/details/52061530

  5. php 二维数组按照某个键排序

    $date = array_column($arr, 'run_date'); //上面得到的结果:array(0=>'2017-11-21',1=>'2017-11-20',3=> ...

  6. Java框架spring Boot学习笔记(一):开始第一个项目

    新建一个项目,选择Spring initializr 修改group和项目名 添加依赖包Web,MongoDB 设置保存位置和工程名 新建一个test的文件 输入代码: package com.xxx ...

  7. Jmeter连接MySQL和SQL Server配置(转载)

    在使用jmeter做性能或自动化测试的时候,往往需要直接对数据库施加压力,或者某些参数只能从数据库获取,这时候就必须使用jmeter连接数据库. 2 下载对应的驱动包 mysql驱动: (mysql- ...

  8. python调用webservice接口

    使用suds这个第三方模块 from suds.client import Clienturl = 'http://ip:port/?wsdl'cilent=Client(url)print cile ...

  9. python的序列类

    1,我们常见的数据结构有哪些是序列类 序列类型的分类: ①  容器序列:list,tuple,deque(可以防止任意的类型的容器) ②  扁平序列:str,bytes,bytearray,array ...

  10. python shell的交互模式和文本编辑模式

    之前学python的时候,是拿<笨办法学python>练习的. 书里面基本都是以.py文件去写代码,也就是文本编辑模式. 而交互模式(也就是powershell),唯有在input用户输入 ...