Radical and array

时间限制: 1 Sec  内存限制: 128 MB
提交: 46  解决: 27
[提交][状态]

题目描述

Radical has an array , he wants the array to have as many equal numbers as possible.
He can performs the following operation as many times as he wants:
1.he chooses two elements of the array a[i] , a[j] (i!=j).
2.he simultaneously increases number a[i] by 1 and decreases number a[j] by 1
Now he want to know what maximum number of equal array elements he can get if he performs an arbitary number of such operation.

输入

The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (ai ≤ 100000) — the original array.

输出

Print a single integer — the maximum number of equal array elements Radical can get if he performs an arbitrary number of the given operation.

样例输入

2
2 3
3
2 4 3

样例输出

1
3

经过任意次,在数组里任意取数,一个数相加,一个数相减后,最多可以得到几个相等的数先求出平均值想必是极好哒。我们当然想尽量把所有数都凑成平均值,如果一定会有的数凑不成,那这些数就可以让我们随意拿来减或者加,以便让其他数减或加凑成平均值。而这些数之和与平均值的余数
#include<iostream>
#include<cstdio>
#include<cstring>using namespace std;#define N 100005int main()
{int n, a[N], sum;while(cin >> n){memset(a, 0, sizeof(a));sum = 0;for(int i = 0; i < n; i++){cin >> a[i];sum += a[i];}int x = sum / n;int y = sum % n;if(y == 0)printf("%d\n", n);else{printf("%d\n", n-1-y/(x+1));}}return 0;
}

转载于:https://www.cnblogs.com/Tinamei/p/4689691.html

Radical and array相关推荐

  1. 老男孩上海校区Python面试题

    python面试题 第一章:python基础 数据类型: 1 字典: 1.1 现有字典 dict={'a':24,'g':52,'i':12,'k':33}请按字典中的 value 值进行排序? 1. ...

  2. php recordarray,Array 数组 - [ php中文手册 ] - 在线原生手册 - php中文网

    用户评论: [#1] florenxe [2015-10-07 18:53:45] //a nice little way to print leap years using array for ($ ...

  3. NumPy — 创建全零、全1、空、arange 数组,array 对象类型,astype 转换数据类型,数组和标量以及数组之间的运算,NumPy 数组共享内存

    NumPy 简介 一个用 python 实现的科学计算包.包括: 1.一个强大的 N 维数组对象 Array : 2.比较成熟的(广播)函数库: 3.用于整合 C/C++ 和 Fortran 代码的工 ...

  4. array.array python yhzf

    关于array: Python 本身没有数组这个说法, 有的就是list和tuple, list就具有其他语言中的数组特性. 至于list和tuple的区别,在于list可以在运行时修改内容和大小,t ...

  5. [JS]请给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组。

    请给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组. 刚开始复习js题还不太习惯 CSDN上看了一个帖子,说是牛客上的标答, ...

  6. hnswlib RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is to sma

    1. 问题现象 index = hnswlib.Index(space = '100', dim = 512) index.init_index(max_elements = 100, ef_cons ...

  7. Array 数组去重 总结10方法(7)

    1,常规双循环去重(缺点:循环次数较多) Array.prototype.unique1 = function(){if(this === null){throw new TypeError('&qu ...

  8. ECMAScript——引用数据类型之array

    array 转载于:https://www.cnblogs.com/cataway/p/4967058.html

  9. leetcode:Search in Rotated Sorted Array

    题目要求: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 ...

最新文章

  1. [深入React] 2.综述
  2. 分布式概念-去中心化副本控制实现
  3. java ios支付接口开发_微信支付接入(Android/IOS(swift)/Java后台)
  4. 动态规划——最长公共子序列(LCS)
  5. redis在mac上的安装
  6. Docker相关的项目
  7. 商品领域ddd_DDD 领域驱动设计-商品建模之路
  8. 2014 年度 Git@OSC 最热门的 50 个项目
  9. python中求根公式_用python做个带GUI的求根公式吧
  10. Atitit path query 路径查询语言 数据检索语言 目录 1.1. List map spel 1 1.2. Html数据 》》Css选择符 1 1.3. Json 》map》
  11. 计算机网络推荐,计算机网络 | CCF推荐 | 国际会议信息4条
  12. 董明珠表示“格力不能更好运营,我绝不交班”,现实由不得她
  13. 如何制作基于beaglebone的设备通知Texter ?---凯利讯半导体
  14. 每周一喂丨图说WiFi安全
  15. Spring 框架之九阴真经
  16. 手把手教你做蓝牙聊天应用(三)-获取要连接的设备
  17. 我的window10中没有Windows Subsystem for Linux
  18. 身为程序员,我敢和你打赌100块,这个数学符号你根本不会认不会写
  19. 在Magento产品分类页面创建推荐产品(Featured Products)
  20. NKOI 1937 太空飞行计划

热门文章

  1. 【STM32】GPIO之蜂鸣器
  2. 【Linux】一步一步学Linux——groupdel命令(88)
  3. ajax get请求_JSP中的对讲机Ajax简述
  4. on java 8学习笔记
  5. Hbase(3)——desc、alter、时间戳
  6. Mysql(6)——数据库中表相关操作(2)
  7. 二叉树的最近公共祖先—leetcode236
  8. can协议解析字符串的原理
  9. Redis Cluster Gossip 协议详解
  10. sklearn训练模型保存与加载