【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 ...
随机推荐
- .net core 中 identity server 4 之Topic --定义Client
客户端指能够从id4获取Token的角色. 客户端的共性: a unique client ID a secret if needed the allowed interactions with th ...
- 实用的 Node.js 教程,工具和资源
这里分享一批实用的实用的 Node.js 教程,工具和资源. Node.js是一个建立在Chrome之上的JavaScript运行时平台,可方便地构建快速,可扩展的网络应用程序.Node.js使用事件 ...
- 【洛谷 P1501】 [国家集训队]Tree II(LCT)
题目链接 Tree Ⅱ\(=\)[模板]LCT+[模板]线段树2.. 分别维护3个标记,乘的时候要把加法标记也乘上. 还有就是模数的平方刚好爆\(int\),所以开昂赛德\(int\)就可以了. 我把 ...
- HDU 1148 Rock-Paper-Scissors Tournament (模拟)
题目链接 Problem Description Rock-Paper-Scissors is game for two players, A and B, who each choose, inde ...
- python小爬虫练手
一个人无聊,写了个小爬虫爬取不可描述图片.... 代码太短,就暂时先往这里贴一下做备份吧. 注:这是很严肃的技术研究,当然爬下来的图片我会带着批判性的眼光审查一遍的.... :) #! /usr/ ...
- webpack中的静态资源处理
你可能已经注意到,在我们的项目结构里,有两个静态文件的路径,分别是:src/assets 和 static/.那这两个到底有什么区别呢? Webpacked 资源 为了回答这个问题,我们首先需要理解w ...
- python并发编程之threading线程(一)
进程是系统进行资源分配最小单元,线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.进程在执行过程中拥有独立的内存单元,而多个线程共享内存等资源. 系列文章 py ...
- 64_p10
python3-matplotlib-qt4-2.0.0-2.fc26.2.x86_64.rpm 05-Apr-2017 09:54 29438 python3-matplotlib-qt5-2.0. ...
- python3.4.3安装allure2记录
一.安装:cmd执行命令pip install allure-pytest 二.下载allure2:2.7.0版本 https://dl.bintray.com/qameta/generic/io/q ...
- MySQL 视图、触发器、函数、存储过程
1. 视图 1.1 什么是视图 通俗来讲,视图就是一条 select 语句执行后返回的结果集.所有我们在创建视图的时候,主要的工作就落在创建这条SQL查询语句上. 1.2 视图的特性 视图是对若干张基 ...