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;
    }
    
  • 相关阅读:
    ccc pool
    ccc 模拟重力 正太分布
    ccc 正态分布
    ccc this 指针
    基本语法HelloWorld
    css选择器
    css基本语法
    表单
    表格
    超链接
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11618448.html
Copyright © 2011-2022 走看看