传送: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(第一天)项目之 注册功能实现通过forms验证与 前端ajax请求触发查询数据库判断用户是否存在的功能实现

    1.BBS项目之注册功能通过forms验证 from django import forms from blog.models import User from django.contrib.auth ...

  2. c#读取文本并生成txt

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. JRebel 代理激活

    1.生成GUID   https://www.guidgen.com/ 例:04cfff79-8f45-481c-a858-a5b9590422e7 2.License Server 例: http: ...

  4. tanera笔记

    use bit operation int i = ...; if ((i & 0x4) != 0) { //倒数第三位是为1 } C++的友元类和友元函数实例 - winfu - 博客园 h ...

  5. 数据库设计,表与表的关系,多对多。Many-To-Many(3)

    多对多:两个数据表里的每条记录都可以和另一个表里的任意数量的记录(或者没记录)相关. 多对多关系是关系数据库中两个表之间的一种关系, 该关系中第一个表中的一个行可以与第二个表中的一个或多个行相关.第二 ...

  6. php-beanstalkd消息队列类分享

    <?php namespace Common\Business; /** * beanstalk: A minimalistic PHP beanstalk client. * * Copyri ...

  7. Fedora 25 安装 Bugzilla

    最近领导要我们装一个Bugzulla,虽然我们项目已经有了JIRA(我就呵呵),不过我还是找些资料安装了,在此备忘. Bugzilla 是一个开源的缺陷跟踪系统(Bug-Tracking System ...

  8. 【c++】内存检查工具Valgrind介绍,安装及使用以及内存泄漏的常见原因

    转自:https://www.cnblogs.com/LyndonYoung/articles/5320277.html Valgrind是运行在Linux上一套基于仿真技术的程序调试和分析工具,它包 ...

  9. [leetcode]22. Generate Parentheses生成括号

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  10. canvas(四) Gradient- demo

    /** * Created by xianrongbin on 2017/3/9. */ /* strokeStyle 或 fillStyle 属性的值*/ /** * Demo1 创建线性渐变 */ ...