题目链接: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. python3中报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'

    reload(sys) sys.setdefaultencoding("utf-8") f = open('.\\24.novel.txt','rb') str = f.read( ...

  2. webservice接口测试wsdl

    http和webservice接口测试有什么区别? webservice的基础组成是http+xml 三要素:soap传输协议,uddi,wsdl(webservice描述语言xml格式) 优点:跨平 ...

  3. ubuntu下安装thrift

    configure: error: "Error: libcrypto required."

  4. 关于break,return,和coutiune

    public boolean searchStudent(String name,int start,int end) { if(students==null) { return false; } f ...

  5. C0气体传感器分析

    1.外观.价格 2.工作原理 MQ-7 CO气体传感器使用的敏感元件为气敏材料(SnO2),该传感器对一氧化碳的灵敏度高. SnO2在洁净空气中电导率低,传感器的电导率随着空气中CO气体浓度增加而增大 ...

  6. kickstart ---无人值守安装

    kickstart 实战 http://man.linuxde.net/download/CentOS_6_9镜像 安装: 关闭防火墙 且在编辑虚拟网络的vnet8中要取消使用本地dhcp项 1.yu ...

  7. ext 的controller中的refs的使用方法

    通过ext api 可以知道ext 的controller中有个refs的属性,对于这个属性 文档上是这么说的:配置数组构建页面上的视图的引用. 我并看不懂,接下来说的是我对这个refs的理解. 对这 ...

  8. C#基础加强(2)之密闭类、静态类及扩展方法

    密闭类 简介 密闭类是被 sealed 关键字修饰的类,密闭类不能有子类.一般只有系统的一些基本类声明为密闭类,例如 String 类. 相关面试题 是否可以编写一个类继承自 String 类? 我们 ...

  9. 本地node启动服务步骤

    启动node服务: 1.git bash here (node server-run.js) 2.如果第一次启动node服务,要根据提示装依赖文件npm install 依赖文件名 3.启动成功提示: ...

  10. Linux下安装Gensim

    依赖软件包:numpy 直接使用pip安装: [root@mycentos ~]#pip install gensim 安装gensim的时候会遇到下面的一系列错误: Cannot uninstall ...