题目大意:将n个数分解成若干组,如4 = 2+2, 7 = 2+2+3,保证所有组中数字之差<=1。

首先我们能想到找一个最小值x,然后从x+1到1枚举并check,找到了就输出。这是40分做法。

能不能优化?我们发现,若k合法,那么x%k==0或x%(k+1)==0或x%(k-1)==0。

所以枚举倍数就行了,利用贪心找到了就输出。

代码:

#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
int n;
ll a[],mn=0x3f3f3f3f;
bool cmp(ll x,ll y)
{
return x<y;
}
void check(ll k)
{
if(!k)return ;
ll ret = ;
for(int i=;i<=n;i++)
{
if(a[i]<k-)return ;
int cnt = a[i]/k+(a[i]%k!=);
if(a[i]%k==)
{
ret+=cnt;
continue;
}
if(k*cnt-a[i]>cnt)return ;
ret+=cnt;
}
printf("%I64d\n",ret);
exit();
return ;
}
int main()
{
// freopen("C.in","r",stdin);
// freopen("C.out","w",stdout);
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%I64d",&a[i]);
mn=min(mn,a[i]);
}
for(int i=;i<=mn;i++)
{
check(mn/i+);
check(mn/i);
check(mn/i-);
}
fclose(stdin);
fclose(stdout);
return ;
}

CF792E Colored Balls的更多相关文章

  1. CF792E Colored Balls【思维】

    题目传送门 考试的时候又想到了小凯的疑惑,真是中毒不浅... 设每一个数都可以被分成若干个$k$和$k+1$的和.数$x$能够被分成若干个$k$和$k+1$的和的充要条件是:$x%k<=floo ...

  2. Codeforces554 C Kyoya and Colored Balls

    C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...

  3. 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 ...

  4. 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 ...

  5. Kyoya and Colored Balls(组合数)

    Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. 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 ...

  7. 554C - Kyoya and Colored Balls

    554C - Kyoya and Colored Balls 思路:组合数,用乘法逆元求. 代码: #include<bits/stdc++.h> using namespace std; ...

  8. 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 ...

  9. Codeforces554C:Kyoya and Colored Balls(组合数学+费马小定理)

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

随机推荐

  1. HTML标签防XSS攻击过滤模块--待优化

    HTML标签防XSS攻击过滤模块 http://cnodejs.org/topic/5058962f8ea56b5e7806b2a3

  2. MFC project for a non-Unicode character set is deprecated

    error MSB8031: Building an MFC project for a non-Unicode character set is deprecated. You must chang ...

  3. bzoj 3196 Tyvj 1730 二逼平衡树【线段树 套 splay】

    四舍五入就是个暴力. 对于线段树的每个区间都开一棵按权值排序的splay 对于第二个操作,二分一下,每次查询mid的排名,复杂度 $ O(nlog(n)^{3}) $ 其余的操作都是$ O(nlog( ...

  4. [App Store Connect帮助]七、在 App Store 上发行(3.2)提交至“App 审核”:查看 App 状态历史记录

    您可以查看您 App 的某一版本的 App 状态历史记录.在历史记录表中的每一行都包含 App 状态.App 状态更改时间,以及更改的发起人.使用此信息追踪“App 审核”流程中的 App. 若想在 ...

  5. ODBC数据管理器 SqlServer实时数据同步到MySql

    ---安装安装mysqlconnector http://www.mysql.com/products/connector/ /* 配置mysqlconnector ODBC数据管理器->系统D ...

  6. LuoguP1314 聪明的质检员 【二分答案/前缀和】

    美丽的题号预示着什么... 描述 小 T 是一名质量监督员,最近负责检验一批矿产的质量.这批矿产共有n个矿石,从1到n逐一编号,每个矿石都有自己的重量wi以及价值vi.检验矿产的流程是: 1.给定m个 ...

  7. python之对堆栈、队列处理操作(转载+个人看法)

    参考链接:https://blog.csdn.net/u010786109/article/details/40649827 python实现堆栈操作 堆栈是一个后进先出的数据结构,其工作方式就像一堆 ...

  8. 【洛谷3343_BZOJ3925】[ZJOI2015]地震后的幻想乡(状压 DP_期望)

    题目: 洛谷 3343 BZOJ 3925 分析: 谁给我说这是个期望概率神题的,明明没太大关系好吧 「提示」里那个结论哪天想起来再问 Jumpmelon 怎么证. 首先,由于开始修路前 \(e_i\ ...

  9. jdk 1.8下 java ArrayList 添加元素解析

    转载请注明http://www.cnblogs.com/majianming/p/8006452.html 有人问我,java ArrayList底层是怎么实现的?我就回答数组,他再问我,那它是怎么实 ...

  10. 里氏替换原则中is和as分别的作用

    is 是用于检查对象是否指定类型兼容 if(empls[i] is SE){ ((SE)empls).SayHi(); } as 不用强转可以直接转换 if(empls[i] is SE){ SE s ...