联萌十一大决战之如日中天 C. Cinderella(灰姑娘新编)

[题目链接] (http://www.bnuoj.com/v3/contest_show.php?cid=6867#problem/C)
题目描述:
C. Cinderella
Time Limit: Unknown msMemory Limit: 262144KB 64-bit integer IO format: %I64d Java class name: (Any)
Submit Status
Input/Output: standard input/output

Cinderella is given a task by her Stepmother before she is allowed to go to the Ball. There are N (1 ≤ N ≤ 1000) bottles with water in the kitchen. Each bottle contains Li (0 ≤ Li ≤ 106) ounces of water and the maximum capacity of each is 109 ounces. To complete the task Cinderella has to pour the water between the bottles to fill them at equal measure.

Cinderella asks Fairy godmother to help her. At each turn Cinderella points out one of the bottles. This is the source bottle. Then she selects any number of other bottles and for each bottle specifies the amount of water to be poured from the source bottle to it. Then Fairy godmother performs the transfusion instantly.

Please calculate how many turns Cinderella needs to complete the Stepmother’s task.

Input
The first line of input contains an integer number N (1 ≤ N ≤ 1000) — the total number of bottles.

On the next line integer numbers Li are contained (0 ≤ Li ≤ 106) — the initial amount of water contained in ith bottle.

Output
Output a single line with an integer S — the minimal number of turns Cinderella needs to complete her task.

Sample Input
Input
3
5 7 7
Output
2
Input
3
21 10 2012
Output
1
Input
1
100
Output
0
言简意赅:
Cinderella 要完成工作才能去参加ball,今晚,可怜的姑娘的工作是均匀分配瓶子中的水,N个瓶子中本来盛有不同量的水,请计算Cinderella要从多少个水多的瓶子(即源瓶)中往外倒水(即大于平均值的水瓶的个数),巨水的一道题,代码实现如下:

#include <iostream>
#include <cstdio>

using namespace std;

int a[1005];
int main()
{
    int n,count;
    long long sum;
    while(scanf("%d",&n)!=EOF)
    {
        sum=0;
        count=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        sum=sum/n;
        for(int i=0;i<n;i++)
        {
            if(a[i]>sum)
            {
                count++;
            }
        }
        printf("%d\n",count);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值