【CF contest/792/problem/E】
E. Colored Ballstime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are n boxes with colored balls on the table. Colors are numbered from 1 to n. i-th box contains ai balls, all of which have color i. You have to write a program that will divide all balls into sets such that:
- each ball belongs to exactly one of the sets,
- there are no empty sets,
- there is no set containing two (or more) balls of different colors (each set contains only balls of one color),
- there are no two sets such that the difference between their sizes is greater than 1.
Print the minimum possible number of sets.
InputThe first line contains one integer number n (1 ≤ n ≤ 500).
The second line contains n integer numbers a1, a2, ... , an (1 ≤ ai ≤ 109).
OutputPrint one integer number — the minimum possible number of sets.
Examplesinput3
4 7 8output5input2
2 7output4NoteIn the first example the balls can be divided into sets like that: one set with 4 balls of the first color, two sets with 3 and 4 balls, respectively, of the second color, and two sets with 4 balls of the third color.
【分析】
先%一下大颓果。。
这种题自己想分配方法都要对拍一下验证啊不然很容易错。。
假设你分成x和x+1,对于某个A来说,判断是否成立的条件是A mod x <= [A / x] 或者 A mod (x+1)==0嘛。。
后面那个直接判断就好了,考虑前面那个代表什么。
就是A-[A/x]*x<=[A/x]
即A/(x+1)<=[A/x] 即 [A/(x+1)]<[A/x]
就是说A/(x+1)和A/x要不一样。
我们去取最小的A,不同的A/x 只有2根号n个,枚举然后for一遍判断就好了。
然后你求出x最大多少,算ans。【我就是这里错了TAT
若ans%(x+1)==0 ,直接分成x+1份。
否则先分成x份,A%x放入每堆中,剩下可能还有很多堆x,每(x+1)堆x的可以变成x堆(x+1)的,所以减掉 剩下的/(x+1),求出答案即可。
时间(根号A * n)
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 510
#define INF 0x7fffffff
#define LL long long int mymin(int x,int y) {return x<y?x:y;}
int mymax(int x,int y) {return x>y?x:y;} int a[Maxn],n; bool check(int x)
{
for(int i=;i<=n;i++)
{
bool p=;
if(a[i]%x==||a[i]%(x+)==||a[i]/x!=a[i]/(x+)) p=;
if(!p) return ;
}
return ;
} int main()
{
// int T;
// scanf("%d",&T);
// while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int mn=INF,ans=;
for(int i=;i<=n;i++) mn=mymin(mn,a[i]);
for(int i=mn;i>=;)
{
if(i<ans) break;
int x=mn/i,r=mn/(x+);
if(check(i)) ans=mymax(ans,i);
i=r;
}
for(int i=;i<=mn;)
{
if(mn/i<ans) break;
int x=mn/i,r=mn/x;
if(check(x)) ans=mymax(ans,x);
else if(check(x-)) ans=mymax(ans,x-);
i=r+;
}
LL sm=;
for(int i=;i<=n;i++)
{
if(a[i]%(ans+)==) sm+=a[i]/(ans+);
else
{
int xx=a[i]/ans,yy=a[i]%ans;
// xx-=yy;
sm+=xx-(xx-yy)/(ans+);
}
// sm+=(a[i]/(ans+1))+(a[i]%(ans+1)!=0);
}
printf("%I64d\n",sm);
}
return ;
}
2017-04-19 10:02:16
【CF contest/792/problem/E】的更多相关文章
- 【cf contest 1119 H】Triple
题目 给出 \(n\) 个三元组\(\{ a_i,b_i,c_i \}\)和\(x,y,z\): 将每个三元组扩展成(\(x\)个\(a_i\),\(y\)个\(b_i\),\(z\)个\(c_i\) ...
- 【cf contest 1119 G】Get Ready for the Battle
题目 你有\(n\)个士兵,需要将他们分成\(m\)组,每组可以为0: 现在这些士兵要去攻打\(m\)个敌人,每个敌人的生命值为\(hp_i\) : 一轮游戏中一组士兵选定一个攻打的敌人,敌人生命值- ...
- 【CF 676B Pyramid of Glasses】模拟,递归
题目链接:http://codeforces.com/problemset/problem/676/B 题意:一个n层的平面酒杯金字塔,如图,每个杯子的容量相同.现在往最顶部的一个杯子倒 t 杯酒,求 ...
- 【CF Round 434 A. k-rounding】
Time limit per test1 second memory limit per test 256 megabytes input standard input output standard ...
- 【CF Round 429 B. Godsend】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF Manthan, Codefest 17 B】Marvolo Gaunt's Ring
[链接]h在这里写链接 [题意] 给你n个数字; 让你在其中找出三个数字i,j,k(i<=j<=k); 使得p*a[i]+q*a[j]+r*a[k]最大; [题解] /* 有一个要 ...
- 【CF Manthan, Codefest 17 A】Tom Riddle's Diary
[链接]h在这里写链接 [题意] 在这里写题意 [题解] /* Be careful. 二重循环枚举 */ [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/st ...
- 【luogu P4137 Rmq Problem / mex】 题解
题目链接:https://www.luogu.org/problemnew/show/P4137 求区间内最大没出现过的自然数 在add时要先判断会不会对当前答案产生影响,如果有就去找下一个答案. # ...
- 【CF edu 30 A. Chores】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
随机推荐
- Centos7系统环境下Solr之Java实战(一)搭建solr服务器
搭建步骤 1.分别上传tomcat.sorl到指定文件夹并解压 2.把solr部署到Tomcat下 通过命令 cp apache-tomcat-7.0.47 /usr/local/sorl/tomca ...
- 拦截asp.net输出流做处理
本文标题是指对已经生成了HTML的页面做一些输出到客户端之前的处理. 方法的原理是:把Response的输出重定向到自定义的容器内,也就是我们的StringBuilder对象里,在HTML所有的向页面 ...
- css3中新增的样式使用方法
在PC版开发中由于IE原因,我们很少用到css3,但随着平板和智能手机进入我们的生活,以及现在越来越流行,在手机版和平板版开发中我们就可以大胆的使用了,下面我们探讨常用几个css3属性: 1.css3 ...
- 【leetcode 简单】第三题 回文数
判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...
- 2017 ACM暑期多校联合训练 - Team 4 1007 HDU 6073 Matching In Multiplication (模拟)
题目链接 Problem Description In the mathematical discipline of graph theory, a bipartite graph is a grap ...
- NASA: SpaceX的猎鹰9号火箭将龙飞船发射到国际空间站
At 5:42 a.m. EDT Friday, June 29, 2018, SpaceX’s Dragon spacecraft lifts off on a Falcon 9 rocket fr ...
- Ubuntu 14.04 开机手动开启numlock led
在windows开机后,数字键盘灯是亮着的,但是当切换到ubuntu系统后登录用户名和密码时,如果你设定的有数字,都要先打开数字键盘区NUMLOCK键,然后再输入了,很不方便. 首先,需要安装一个小软 ...
- 作为一个新手的Oracle(DBA)学习笔记【转】
一.Oracle的使用 1).启动 *DQL:数据查询语言 *DML:数据操作语言 *DDL:数据定义语言 DCL:数据控制语言 TPL:事务处理语言 CCL:指针控制语言 1.登录 Win+R—cm ...
- Deep Learning基础--理解LSTM/RNN中的Attention机制
导读 目前采用编码器-解码器 (Encode-Decode) 结构的模型非常热门,是因为它在许多领域较其他的传统模型方法都取得了更好的结果.这种结构的模型通常将输入序列编码成一个固定长度的向量表示,对 ...
- linux系统定时任务设置
.使用at命令设置一次性定时任务 2.使用crontab设置周期性定时任务 1)cd /home 目录下,使用vi test.py创建文件,内容如下: #!/usr/bin/python#coding ...