Codeforces 792 E. Colored Balls
题目链接: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的更多相关文章
- 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 ...
- 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 ...
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 ...
- 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 ...
- 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 ...
- codeforces 553 A Kyoya and Colored Balls
这个题.比赛的时候一直在往dp的方向想,可是总有一个组合数学的部分没办法求, 纯粹组合数学撸,也想不到办法-- 事实上,非常显然.. 从后往前推,把第k种颜色放在最后一个,剩下的k球.还有C(剩余的位 ...
- 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 ...
随机推荐
- Ubuntu常用操作命令
解压文件: tar -zxvf 文件名 -C 指定目录 从当前环境进入root环境: su,然后输入root密码
- php(数组方法
什么是数组? 数组就是一组数据的集合 其表现形式就是内存中的一段连续的内存地址 数组名称其实就是连续内存地址的首地址 关于js中的数组特点 数组定义时无需指定数据类型 数组定义时可以无需指定数组长度 ...
- java JVM虚拟机
JVM垃圾处理方法(标记清除.复制.标记整理) 1.标记清除 标记阶段:先通过根节点,标记所有从根节点开始的对象,未被标记的为垃圾对象. 清除阶段:清除所有未被标记的对象. 2.复制算法 将原有的空间 ...
- BOM设计的一些问题及解决方案探讨----合版BOM
BOM是ERP的核心资料,也是比较难的一块,不仅涉及的内容多,要求准确性高,时效性也要求高.但传统的ERP在处理BOM时有不少问题,因此也有些软件公司引入了各种BOM类型,像"标准BOM&q ...
- 实际体验Span<T> 的惊人表现
前言 最近做了一个过滤代码块功能的接口.就是获取一些博客文章做文本处理,然后这些博客文章的代码块太多了,很多重复的代码关键词如果被拿过来处理,那么会对文本的特征表示已经特征选择会有很大的影响.所以需要 ...
- dataTransfer对象
HTML5拖拽的数据传输 虽然通过dragstart.drag和dragend事件实现了原生拖拽.但是这仅仅是拖拽,在IE6和IE7中还是有些拖拽问题,并且也没有实现数据的交换.为了实现数据的交换,I ...
- redis问题与解决思路
问题现象: 集群状态 1主 2从,主没有开启bgsave,从开启bgsave.现象所有redis可以访问,进行操作.主不断开始bgsave 1从停止bgsave. 主日志报错# Connection ...
- gcc update in centos to 6.3 by scl
CentOS 7虽然已经出了很多年了,但依然会有很多人选择安装CentOS 6,CentOS 6有些依赖包和软件都比较老旧,如今天的主角gcc编译器,CentOS 6的gcc版本为4.4,CentOS ...
- Restful API设计规范
理解RESTful架构 Restful API设计指南 理解RESTful架构 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件"采用客户端/服务器模式 ...
- PHP实现 手机号码归属地查询
在工作中需要对手机号码进行归属地查询,就在网上找了下解决方案,发现通过号段非常好判断. 我将数据库文件放到了百度网盘,请有需要的朋友去下载. 链接: https://pan.baidu.com/s/1 ...