Codeforces gym101612 E.Equal Numbers(贪心)
传送: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(贪心)的更多相关文章
- Codeforces.GYM101612E.Equal Numbers(贪心)
题目链接 \(Description\) 给定\(n\)个数,每次可以将任意一个数乘上任意一个正整数. 求\(k\)次操作后,数列中数的种类最少可以是多少.对每个\(0\leq k\leq n\)输出 ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- Codeforces 1065C Make It Equal (差分+贪心)
题意:n个塔,第i个塔由$h_i$个cube组成,每次可以切去某高度h以上的最多k个cube,问你最少切多少次,可以让所有塔高度相等 k>=n, n<=2e5 思路:差分统计每个高度i有的 ...
- Codeforces Round #479 (Div. 3) C. Less or Equal (排序,贪心)
题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排 ...
- Codeforces 798D Mike and distribution - 贪心
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...
- Codeforces H. Maximal GCD(贪心)
题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 1119E Pavel and Triangles (贪心)
Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal t ...
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
随机推荐
- E0264 Unable to execute '"/usr/bin/codesign" ...'
E0264 Unable to execute '"/usr/bin/codesign" ...' http://docwiki.embarcadero.com/RADStudio ...
- Redux-persist使用
redux-persist作用是将store中的数据缓存到浏览器中,减少数据请求,每当白名单中的数据发生变化,才会进行一次更新缓存的操作,并且这个数据缓存是存在localStorage中的,不是会话级 ...
- Controller层aop
利用@Around通知修改Controller的返回值 自定义一个注解@OperationBtn 在切入点Controller上加上自定义注解 接下来就是重点了,AspectJ写切面类,对该Contr ...
- a链接的onclick与js中的return false
在学习<javascript基础教程>第八版时,有一个小细节开始不是很明白,查了一些资料后,理了一下思路. 例子的html代码: <!DOCTYPE html> <htm ...
- js鼠标相关事件
- zabbix监控内存占前3位的进程信息
一.编写shell脚本 ps aux|sort -k4nr|head -3|awk 'split($11,a,"/"){print $4","a[length( ...
- Tomcat9 在Windows中配置允许远程访问
环境:Windows Server 2019 Data Center+Tomcat 9 Tomcat在Windows中安装好了之后,默认只能从本机以http://localhost:8080的方式访 ...
- centos7-内核版本降级
1. 查看内核版本参考命令: [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [roo ...
- Python人工智能之路 - 第三篇 : PyAudio 实现录音 自动化交互实现问答
Python 很强大其原因就是因为它庞大的三方库 , 资源是非常的丰富 , 当然也不会缺少关于音频的库 关于音频, PyAudio 这个库, 可以实现开启麦克风录音, 可以播放音频文件等等,此刻我们不 ...
- pythonj基础(五)元组和集合
一,什么是元祖 Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可. 1.创建一个空元组 tu ...