zoukankan      html  css  js  c++  java
  • Codeforces Round #590 (Div. 3) A. Equalize Prices Again

    链接:

    https://codeforces.com/contest/1234/problem/A

    题意:

    You are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs ai coins.

    You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all n goods you have.

    However, you don't want to lose any money so you want to choose the price in such a way that the sum of new prices is not less than the sum of the initial prices. It means that if you sell all n goods for the new price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.

    On the other hand, you don't want to lose customers because of big prices so among all prices you can choose you need to choose the minimum one.

    So you need to find the minimum possible equal price of all n goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.

    You have to answer q independent queries.

    思路:

    就求个平均值向上取整.

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int t;
        scanf("%d", &t);
        while (t--)
        {
            int n, sum = 0, a;
            scanf("%d", &n);
            for (int i = 1;i <= n;i++)
                scanf("%d", &a), sum += a;
            printf("%d
    ", (sum+n-1)/n);
        }
    
        return 0;
    }
    
  • 相关阅读:
    Linux 搭建SVN server
    GREENPLUM简单介绍
    监听手机录音
    Java NIO与IO的差别和比較
    元数据驱动思考实例分析
    jQuery推断复选框是否勾选
    BitBlt介绍
    Android灭亡论之Firefox OS操作系统出现
    CEGUI添加自定义控件
    IFrame和Ajax比較
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11618448.html
Copyright © 2011-2022 走看看