首页 > 其他 > 详细

Codeforces Round #590 (Div. 3) A. Equalize Prices Again

时间:2019-10-02 21:37:11      阅读:338      评论:0      收藏:0      [点我收藏+]

链接:

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\n", (sum+n-1)/n);
    }

    return 0;
}

Codeforces Round #590 (Div. 3) A. Equalize Prices Again

原文:https://www.cnblogs.com/YDDDD/p/11618448.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!