题目链接: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. 通过Navicat远程连接MySQL

    参考: http://blog.csdn.net/apple9005/article/details/53033148 问题一:在主机下通过Navicat连接服务器MySql的时候,提示“2003 C ...

  2. 转 docker创建私有仓库和k8s中使用私有镜像

    docker私有仓库建立 环境说明我们选取192.168.5.2做私有仓库地址yum install docker -y1.启动docker仓库端口服务 docker run -d -p 5000:5 ...

  3. 内购审核被拒-[environment-sandbox]

    内购审核被拒-[environment-sandbox] 先把新创建的项目提交审核通过后再提交主包 注意,新增加的内购项目要截图告诉苹果

  4. mysql脚本手动修改成oracle脚本

    今天有一个需求,立了一个新项目,新项目初步定了使用了现有的框架,但数据库要求由原来的mysql改成oracle,所以原来的基础版本的数据库脚本就需要修改成符合oracle的脚本,修改完成后,总结了一下 ...

  5. asp.net NPOI导出xlsx格式文件,打开文件报“Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃”

    NPOI导出xlsx格式文件,会出现如下情况: 点击“是”: 导出代码如下: /// <summary> /// 将datatable数据写入excel并下载 /// </summa ...

  6. 详解FPGA中的建立时间与保持时间

    概念对于一个数字系统而言,建立时间和保持时间可以说是基础中的基础,这两个概念就像是数字电路的地基,整个系统的稳定性绝大部分都取决于是否满足建立时间和保持时间.但是对于绝大部分包括我在内的初学者来说,建 ...

  7. java框架之SpringBoot(6)-Restful风格的CRUD示例

    准备 环境 IDE:Idea SpringBoot版本:1.5.19 UI:BootStrap 4 模板引擎:thymeleaf 3 效果:Restful 风格 CRUD 功能的 Demo 依赖 &l ...

  8. GlusterFS配置及使用

    一.GlusterFS 配置及使用 GlusterFS配置及使用:https://www.cnblogs.com/sxchengchen/p/7805667.html 二.CentOS 7 安装部署 ...

  9. 2018-2019-1 20189203《Linux内核原理与分析》第四周作业

    第一部分 课本学习 内核版本号:Linux内核自2013年12月起,就以A.B.C.D的方式命名.A和B变得无关紧要,C是内核的真实版本.每一个版本的变化都会带来新的特性,如内部API的变化等,改动的 ...

  10. Git 在 windows 上面的安装

    参考博客: https://blog.csdn.net/xiezhongyuan07/article/details/79411299 将该作者的文章搬过来, 大家可以直接看上面的原文章. 下面是拷贝 ...