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 ...
随机推荐
- Java 就业班 Web框架
- Java中的包装数据类型
基本类型 包装器类型 boolean Boolean char Character int Integer byte Byte short Short long Long float Float do ...
- SpringCloud-day02-服务消费者项目建立
4.4microservice-ticket-consumer-80服务消费者项目建立 我们新建一个服务器提供者module子模块,类似前面建的common公共模块,名称是 microservice- ...
- Java学习笔记(十八):static关键字
- oracle用户间表数据复制迁移
如system用户要将scott中的emp表倒入其中,按如下方法: 1.登录scott用户 2.给system用户赋予查询emp标的权限: grant select on emp to system; ...
- Eclipse 创建Android 模拟器失败:no cpu/abi system image available for this target
(从网上搜了一个使用Android 4.4 API 20编译的图片) 这是因为SDK中没有模拟器使用的操作系统镜像. 如果项目使用API 19编译,则SDK中的system-images文件夹下,需要 ...
- 31. Next Permutation 返回下一个pumutation序列
[抄题]: Implement next permutation, which rearranges numbers into the lexicographically next greater p ...
- Swift 反射机制,命名空间
1. 知道 Swift 中有命名空间 - 在同一命名空间下,全局共享! - 第三方框架使用 Swift 如果直接拖拽到项目中,从属同一个命名空间,很有可能冲突! ...
- Agile PLM 表结构说明
1. Activity:项目表class表示大类(关口和活动),subclass表示小类(关口,任务,计划,阶段)subclass=18027:计划(项目),subclass=18028:阶段, ...
- SQL Server 2008 R2 根据.asmx访问WebService
.asmx 都是.Net 同系列,所以学习的时候会比较简单. 方法一: 步骤1.在浏览器打开.asmx地址可以到方法列表, 步骤2.点进方法列表会有SOAP调用的案例, 步骤3.SQL Server ...