zoukankan      html  css  js  c++  java
  • Codeforces gym 100685 C. Cinderella 水题

    C. Cinderella
    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/gym/100685/problem/C

    Description

    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

    3
    5 7 7

    Sample Output

    2

    HINT

    题意

    每一个回合可以选择一瓶水然后给其他杯子倒水,然后问你最少几个回合可以使得所有的杯子里面的水都一样

    题解

    求一个平均数,然后大于平均数的就直接倒水就好了

    代码

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 2000001
    #define mod 1000000007
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    
    ll sum=0;
    ll a[maxn];
    int main()
    {
        int n=read();
        for(int i=0;i<n;i++)
            a[i]=read(),sum+=a[i];
        ll kiss=sum/n;
        int ans=0;
        for(int i=0;i<n;i++)
            if(a[i]>kiss)
                ans++;
        cout<<ans<<endl;
    }
  • 相关阅读:
    献给初学者:谈谈如何学习Linux操作系统
    Spring MVC 教程,快速入门,深入分析
    缓存、缓存算法和缓存框架简介
    计算机科学中最重要的32个算法
    12岁的少年教你用Python做小游戏
    当你输入一个网址的时候,实际会发生什么?
    java程序员从笨鸟到菜鸟之(七)一—java数据库操作
    java中的类修饰符、成员变量修饰符、方法修饰符。
    Java内存分配全面浅析
    Java知多少(19)访问修饰符(访问控制符)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4702807.html
Copyright © 2011-2022 走看看