传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的k的答案. 注意这k步不一定是连续的. 分析: 对于每个数,可以有两种操作: 1. 先将有倍数的数变成它们的最大倍数,而且按照出现次数比较少的先变. 2. 将所有数都变成lcm,而且按照出现次数比较少的先变. 数组f[i]代表,操作i次的最小种类数.对于每一次操作,取min. #include<bi…
题目链接 \(Description\) 给定\(n\)个数,每次可以将任意一个数乘上任意一个正整数. 求\(k\)次操作后,数列中数的种类最少可以是多少.对每个\(0\leq k\leq n\)输出答案. \(n\leq 3\times10^5,a_i\leq10^6\). \(Solution\) 有两种贪心策略,一是每次找一个出现次数最少的数,把它变成所有数的LCM:二是找一个出现次数最少,且它的某个倍数存在于原数列里的数,将它变成它的这个倍数. 对两种情况取\(\min\)即可. //9…
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and…
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的货币越优.如有1,2,5,10,20,50,那么我们尽量用面值为1的.如果我们把原始货币换成面值为x的货币,设汇率为d,那么需要的原始货币为dx的倍数.显然dx越小,剩下的钱,即n取模dx会尽量小. 然后就可以枚举换某一种货币的数量,时间复杂度\(O(\frac{n}{d})\) 代码 #inclu…
题意:n个塔,第i个塔由$h_i$个cube组成,每次可以切去某高度h以上的最多k个cube,问你最少切多少次,可以让所有塔高度相等 k>=n, n<=2e5 思路:差分统计每个高度i有的方块数nh[i],然后从高到低贪心的切就行了 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include…
题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排个序,然后首先要注意\(k=0\)的情况 如果\(k=0\)并且序列中含有\(1\),那么我们无论如何都找不到比\(1\)小的数,输出\(-1\),如果不含\(1\),那么只要输出\(a[1]-1\)即可. 如果\(k\ne 0\),那么我们要找前\(k\)个小的数(连续相等的数也算),所以我需要用…
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, …
题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a…
Codeforces Global Round 2 题目链接: E. Pavel and Triangles Pavel has several sticks with lengths equal to powers of two. He has \(a_0\) sticks of length \(2^0=1\), \(a1\) sticks of length \(2^1=2\), ..., \(a_{n−1}\) sticks of length \(2^{n−1}\). Pavel wa…
1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1-9每个字母分别要ai升油漆,问最多可画多大的数字. 贪心,也有点考思维. #include<bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f int main() { ]; while(…