Codeforces Round #511 (Div. 2)】的更多相关文章

Codeforces Round #511 (Div. 2) #include <bits/stdc++.h> using namespace std; int n; int main() { cin>>n; )%) cout<<<<endl; <<endl; } A. Little C Loves 3 I #include <bits/stdc++.h> using namespace std; int n; int main()…
C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让剩下数的gcd变大. 题解: 首先可以先让所有数都除以他们的gcd,让他们互质,好让问题简单化. 由唯一分解定理,题目中的问题可以转化为:找出最多数都共有的质因子,假设其数目为mx,答案就是n-mx. 上面的想法也是基于贪心,具体做法还是有点技巧,就是在筛素数的时候就进行判断,具体见代码吧: #in…
传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一开始想把每个数的因子都找出来,找到这些因子中出现次数最多且因子大于n个数的最大公约数的,(n - 次数 )就是答案.但是复杂度是1e9,差那么一点. 自己还是对素数筛理解的不够深.这道题可以枚举素数x,对于每个x,找到所有(a[i]/gcd(all)) 是x倍数的个数,就是一个次数.找这个次数的过程…
题意 一棵 \(n\) 个点的树,每个点有权值 \(a_i\) .你想砍树. 你可以砍任意次,每次你选择一些边断开,需要满足砍完后每个连通块的权值和是相等的.求有多少种砍树方案. \(n \le 10^6, a_i \le 10^9\) 题解 先假设只砍一次.令所有点权和为 \(S\) ,那么假设要砍成 \(k\) 个连通块,则每个连通块的权值和均为 \(\displaystyle \frac{S}{k}\) . 考虑如何得到砍的方案,以 \(1\) 号点为根 \(dfs\) ,若当前点 \(i…
嗯切一题走人很开心. gzy-50分比我还惨. 题意:有n个数,去掉尽量少的数使得剩下数的gcd变大. 首先把这n个数都除以gcd,就变成了去掉尽量少的数使得gcd不等于1. 可以枚举一个质数,然后统计这个质数是a数组中多少个数的约数. 线性筛,记录每个数最小的约数,每次除以约数,\(O(n\log a)\). Time Limit Exceeded on pretest 8 线性筛的时候顺便记录每个数去掉重复约数之后的数 \(2*3*5*7*11*13*17*19\),再乘23就炸了 每个数最…
只写了AB,甚至还WA了一次A题,暴露了蒟蒻的本质=.= 感觉考的时候有好多正确或和正解有关的思路,但是就想不出具体的解法或者想的不够深(长)(怕不是过于鶸) 话说CF的E题怎么都这么清奇=.= A.Little C Loves 3 I 随便拆一下就好了,大概全场就我一个心太急写挂了一次TAT #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main () {…
题目: Mr. F has nn positive integers, a1,a2,…,an. He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers. But this problem is too simple for him, so he does not want to do it by…
题目: There are nn points on the plane, (x1,y1),(x2,y2),…,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn). You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the s…
题目: Little C loves number «3» very much. He loves all things about it. Now he has a positive integer nn. He wants to split nn into 3 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 3 integers is a multiple of 3. Help him to fin…
题目链接 题目就是找每个数的最小素因子,然后递归除,本来没啥问题,结果今天又学习了个新坑点. 我交了题后,疯狂CE,我以为爆内存,结果是,我对全局数组赋值, 如果直接赋值,会直接在exe内产生内存,否则只会在运行时才分配内存. #include <bits/stdc++.h> using namespace std; ; //线性素数筛 ],num_prime = ; int vis[maxn]; void is_prime(int N) { ;i<N;i++) { if(!vis[i]…