【CF792E】Colored Balls(数论分块)】的更多相关文章

题目链接 大意 有\(N\)种颜色的球,第\(i\)种球有\(Ai\)个,要求把球分成几个集合,使得: 一个集合里的球只能有一种颜色. 任意两个集合的球的数量相差不能超过1. 求这些球至少需要分几个集合. 思路 我们设这些集合的大小为\(Ans\)与\(Ans+1\),考虑如何判断一个\(Ans\)是否可行. 由于一个集合里只能有一种颜色,所以我们可以对于每一种颜色都单独考虑. 设当前颜色为\(i\),我们设 \(Ai=X\cdot Ans+ Y\),其中\(Ans,Y\)满足\(Ans>Y\)…
题目大意:将n个数分解成若干组,如4 = 2+2, 7 = 2+2+3,保证所有组中数字之差<=1. 首先我们能想到找一个最小值x,然后从x+1到1枚举并check,找到了就输出.这是40分做法. 能不能优化?我们发现,若k合法,那么x%k==0或x%(k+1)==0或x%(k-1)==0. 所以枚举倍数就行了,利用贪心找到了就输出. 代码: #include<cstdio> #include<algorithm> using namespace std; #define l…
题目传送门 考试的时候又想到了小凯的疑惑,真是中毒不浅... 设每一个数都可以被分成若干个$k$和$k+1$的和.数$x$能够被分成若干个$k$和$k+1$的和的充要条件是:$x%k<=floor(x/k)$ 又因为$k$一定小于这个数列中最小的那个数,可以轻易想到的一个朴素的方法就是从$1$到$A_{min}$枚举所有可能的$k$,判断是否满足情况,并更新答案. 注意到$k$越大,答案越优,所以从大到小进行枚举,找到答案就退出. 我们现在来优化他: 可以想到,当$k<=\sqrt{x}$,上…
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d      Java class name: (Any) Submit Status Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labele…
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he…
C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/problem/C Description Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k.…
Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 …
C. Kyoya and Colored Balls Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag i…
[BZOJ1257]余数之和(数论分块,暴力) 题解 Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + - + k mod n的值,其中k mod i表示k除以i的余数.例如j(5, 3)=3 mod 1 + 3 mod 2 + 3 mod 3 + 3 mod 4 + 3 mod 5=0+1+0+3+3=7 Input 输入仅一行,包含两个整数n, k. Output 输出仅一行,即j(n, k). Sample Input…
题意 题目链接 Sol 这题是来搞笑的吧.. 考虑一个数的贡献是\(O(\frac{N}{i})\) 直接数论分块. #include<bits/stdc++.h> #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) #define fi first #define se second #define int long long #define LL long long #define ull unsigned…