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;
    }
    
  • 相关阅读:
    视图与URL配置--Hello world
    初始Django
    Django 学习之前提
    MySQL--解决中文乱码
    第二课时之c#语言基础
    第一课时之c#程序设计概述
    hdu--1029--思维题
    hdu--1028--dp||递推||母函数
    hdu--1026--bfs&&优先队列&&打印路径
    hdu--1027-next_permutation||dfs
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11618448.html
Copyright © 2011-2022 走看看