题目链接:http://codeforces.com/contest/792/problem/E


  假设含球较少的那些堆有 $mi$ 个球,较多的那些堆有$ma$个球,$ma=mi+1$,考虑对于最小的$a_i$枚举值 $mi$ ,表示我要将这堆求分成${\left \lfloor \frac{a_i}{k} \right \rfloor}$堆,每一堆$k$个,那么这种颜色就会有${{a_i ~~ mod ~~k}}$个球多出来,所以当且仅当 ${{\left \lfloor \frac{a_i}{k} \right \rfloor\geq (a_i ~~ mod ~~k)}}$ 才合法,然后对于剩下的$n-1$种颜色的判断一下这个$k$值是否合法,统计一下总数,因为这样的$k$对于最小的${a_i}$只有根号种取值,所以复杂度为${O(n* \sqrt 1e9)}$

  注意一下这种trick:答案爆$int$,枚举合法的$k$的时候要再判断一下${ai/k+1}$(样例),最后在算的时候是优先一堆放$ma$个的。

  

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 100100
#define llg int
#define LL long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,c[maxn],tail,a[maxn];
LL ans=(LL)1e16; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} int main()
{
yyj("ball");
cin>>n;
for (llg i=;i<=n;i++) a[i]=getint();
sort(a+,a+n+);
llg up=sqrt(a[]+0.5);
for (llg i=;i<=up;i++) if (a[]/i>=a[]%i) c[++tail]=i;
for (llg i=;i<=up;i++)
{
llg k=a[]/i;
if (a[]/k>=a[]%k) c[++tail]=k;
k--; if (!k) continue;
if (a[]/k>=a[]%k) c[++tail]=k;
}
for (llg i=;i<=tail;i++)
{
llg k=c[i];
bool pd=;
for (llg j=;j<=n;j++) if (a[j]/k<a[j]%k) pd=false;
if (pd)
{
LL sum=;
for (llg j=;j<=n;j++) sum+=a[j]/(k+)+(a[j]%(k+)!=);
ans=min(ans,sum);
}
}
cout<<ans;
return ;
}

Codeforces 792 E. Colored Balls的更多相关文章

  1. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合

    C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  2. C. Kyoya and Colored Balls(Codeforces Round #309 (Div. 2))

    C. Kyoya and Colored Balls Kyoya Ootori has a bag with n colored balls that are colored with k diffe ...

  3. 【47.95%】【codeforces 554C】Kyoya and Colored Balls

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. Codeforces A. Kyoya and Colored Balls(分步组合)

    题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. codeforces 553A . Kyoya and Colored Balls 组合数学

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  6. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  7. codeforces 553A A. Kyoya and Colored Balls(组合数学+dp)

    题目链接: A. Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes i ...

  8. codeforces 553 A Kyoya and Colored Balls

    这个题.比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求, 纯粹组合数学撸,也想不到办法-- 事实上,非常显然.. 从后往前推,把第k种颜色放在最后一个,剩下的k球.还有C(剩余的位 ...

  9. CF-weekly4 F. Kyoya and Colored Balls

    https://codeforces.com/gym/253910/problem/F F. Kyoya and Colored Balls time limit per test 2 seconds ...

随机推荐

  1. 电子产品使用感受之———我用过的最昂贵的手机壳:otter box 和 Apple 原装清水壳的对比

    2014年9月27日,我买到了我所使用的第一部 iPhone — iPhone 5C 蓝色.今天,2019年3月2日,我手里拿的是iPhoneXR 蓝色,两款手机如出一辙的设计和手感,让我充满了无限的 ...

  2. 单片机小白应该如何学习stm32的一些实践心得!

    嵌入式搬砖道路上的大三狗一枚,撑死算个初学者吧.才学有限,下面仅仅是本人对STM32学习的一点心得与建议,希望对题主有帮助吧. 心得:本人当初学习STM32的时候有一些跟风的因素,自以为学的芯片越多就 ...

  3. ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接

    Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\P ...

  4. Ecplise通过Git将项目提交到GitHub

    一.参考https://blog.csdn.net/bendanany/article/details/78891804 二.注意点: 1.仓库名必须和项目名相同: 2.若提交出现Can't conn ...

  5. webstorm项目的structure

    https://www.jetbrains.com/help/webstorm/2016.1/symbols.html

  6. Ajax取PHP JSON数据并显示

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  7. [摘抄] Bezier曲线、B样条和NURBS

    Bezier曲线.B样条和NURBS,NURBS是Non-Uniform Rational B-Splines的缩写,都是根据控制点来生成曲线的,那么他们有什么区别了?简单来说,就是: Bezier曲 ...

  8. 公众号获取unionid

    然后在微信客户端输入unionid接口的地址(比如发给文件传输助手www.XXX.COM/unionid.php),随便给别人发过去,在点击该链接,就能看到打印的accessToken,openid, ...

  9. word之常用功能

    0.word区域:标题栏.快速访问工具栏.功能区.功能按钮.导航窗口.编辑区.水平垂直滑动条.状态栏 1.更改office主题.文件---帐户---office主题.(传统白色.浅灰色.深灰色) 2. ...

  10. Key in_hidden/batch_normalization/beta not found in checkpoint

    可能原因:不同参数的结果保存到了同一文件夹下 解决方法:不同参数结果放在不同的checkpoints tf.train.Saver().save(sess, self.checkpoint_dir + ...