equal numbers
给你一个n长度的数组,让你修改0到n次,问每次修改后能剩下不同个数的最小数是多少;
这里有了两种做法,一种是变成他们的lcm这样的话,修改后答案应该是减去改过的个数然后在加一
另一种就是数字修改成序列中的倍数,比如如果序列中有4和8,修改一次把4变成8,这样剩下的数字就只有一个;比较这两个做法,找出更小的就好了
做法就是,一种把原来次数从小到大排序,然后一个个变,另一种就是把能变成序列中其他数字的数的个数从小到大排,然后一次次跑就可以了
#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define si(a) a.size()
#define vi vector<int>
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define mm(x,b) memset((x),(b),sizeof(x))
#define IO(x) freopen("x.in","r",stdin);freopen("x.out","w",stdout);
#define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
typedef long long ll;
using namespace std;
const double eps=1e-8;
const int N=3e5+2;
map<int,int> mp;
int a1[N],a2[N];
int main()
{
IO(equal);
int n;scf(n);
int maxn=0;
rep(i,0,n)
{
int x;scf(x);
maxn=max(maxn,x);
mp[x]++;
}
int tot1=0,tot2=0;
rep(i,1,maxn+1)
{
if(mp[i])
{
a1[tot1++]=mp[i];
for(int j=i+i;j<=maxn;j+=i)
{
if(mp[j])
{
a2[tot2++]=mp[i];
break;
}
}
}
}
sort(a1,a1+tot1);
sort(a2,a2+tot2);
cout<<tot1;
int sum1=0,sum2=0;
int pos1=0,pos2=0;
rep(i,1,1+n)
{
while(pos1<tot1&&sum1+a1[pos1]<=i)
sum1+=a1[pos1++];
while(pos2<tot2&&sum2+a2[pos2]<=i)
sum2+=a2[pos2++];
int ans=min(tot1-pos1+1,tot1-pos2);
if(ans==0) ans=1;
cout<<" "<<ans;
}
return 0;
}
equal numbers的更多相关文章
- Codeforces gym101612 E.Equal Numbers(贪心)
传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的 ...
- Codeforces.GYM101612E.Equal Numbers(贪心)
题目链接 \(Description\) 给定\(n\)个数,每次可以将任意一个数乘上任意一个正整数. 求\(k\)次操作后,数列中数的种类最少可以是多少.对每个\(0\leq k\leq n\)输出 ...
- Equal Numbers Gym - 101612E 思维
题意: 给你n个数vi,你有k次操作.每一次操作你可以从n个数里面挑一个数,然后使得这个数乘于一个正整数.操作完之后,这n个数里面不同数的数量就是权值.你要使得这个值尽可能小. 题解: 如果a%b== ...
- CF 370B Berland Bingo
题目链接: 传送门 Berland Bingo time limit per test:1 second memory limit per test:256 megabytes Descrip ...
- [ACM_动态规划] ZOJ 1425 Crossed Matchings(交叉最大匹配 动态规划)
Description There are two rows of positive integer numbers. We can draw one line segment between any ...
- [转载] Calculating Entropy
From: johndcook.com/blog For a set of positive probabilities pi summing to 1, their entropy is defi ...
- Poj 1029 分类: Translation Mode 2014-04-04 10:18 112人阅读 评论(0) 收藏
False coin Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16418 Accepted: 4583 Descr ...
- USACO 2014 Open Silver Fairphoto
这道题只是银牌组的第一题而我就写了 3K 的代码.唉. Description - 问题描述 FJ's N cows (2 <= N <= 100,000) are standing at ...
- UVA 1175 Ladies' Choice 稳定婚姻问题
题目链接: 题目 Ladies' Choice Time Limit: 6000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 问题 ...
随机推荐
- 使用js解决response.sendRedirect("...")重定向URL之后出现跨域问题
背景: 本系统与门户系统单点登录时候,需要重定向到门户系统的登录页面,可是如果长时间没有操作的话,session会话失效,就需要跳转到登录页面. 所以在使用 response.sendRedirect ...
- Subversion和TortoiseSVN,VisualSVN图文教程
转自:http://www.veryhuo.com/a/view/156054.html 本文为大家介绍一下SVN使用教程,在开始之前,您有必要了解一下为什么要使用SVN?因为程序员在编写程序的过程中 ...
- 爬虫之 BeautifulSoup与Xpath
知识预览 BeautifulSoup xpath BeautifulSoup 一 简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: '' ...
- 定制centos6.5自动安装ISO光盘
一 ISO定制项清单 安装系统为centos6.5 (base server),安装方式为全新安装 使用ext4分区格式 安装前可以交互输入root密码,主机名,swap分区大小,之后安装过程自动化 ...
- Return local beginning of day time object in Go
Both the title and the text of the question asked for "a local [Chicago] beginning of today tim ...
- 2019-2020-1 20199301《Linux内核原理与分析》第二周作业
第二周Linux学习笔记 文件打包与解压缩 tar工具打包 tar的解压和压缩都是同一个命令,只需参数不同,使用较方便. 创建一个包时文件名必须紧跟在 -f 之后,解包一个文件(-x参数)到指定路径的 ...
- 2019-2020-1 20199301《Linux内核原理与分析》第一周作业
学习内容 搜查文件 刚添加的文件有时候会找不到 解决方案:新添加的文件要手动执行一次updatedb更新,就可以搜查到文件 查找某目录下的所有文件添加 * 号前面的反斜杠不能忘记打上,否则会无法找到 ...
- 01 - Element
¶安装 npm 安装 推荐使用 npm 的方式安装,它能更好地和 webpack 打包工具配合使用. npm i element-ui -S CDN 目前可以通过 unpkg.com/element- ...
- 洛谷 P2038 无线网络发射器选址 题解
每日一题 day9 打卡 Analysis 这道题是个模拟,两个0~128( 注意不是1~128 )的循环枚举正方形中心点,判断正方形的边界,再用循环枚举公共场所的数量就好了. 时间复杂度 < ...
- MongoDB新存储引擎WiredTiger实现(事务篇)
导语:计算机硬件在飞速发展,数据规模在急速膨胀,但是数据库仍然使用是十年以前的架构体系,WiredTiger 尝试打破这一切,充分利用多核与大内存时代,开发一种真正满足未来大数据管理所需的数据库.本文 ...