Equalize Prices Again
题面翻译
题目大意
有n个商品,其中第i个商品的成本为a_i。
现在要求你求出一个平均价格,使得每件商品按照此平均价格卖出后不亏本,而且赚到的钱最少(挣的钱可以为0)
注意题目有多组数据。
输入格式
第一行输入数据组数q(1≤q≤100,q为整数)。
接下来q组数据。对于每组数据,先输入商品个数n(1≤n≤100,n为整数),接下来一行包含n个整数:a_1,a_2,... ... ,a_n,其中a_i表示第i个商品的成本。
输出格式
对于每组数据,每行输出一个平均价格。
Translated by @夙_愿扬
题目描述
You are both a shop keeper and a shop assistant at a small nearby shop. You have $ n $ goods, the $ i $ -th good costs $ a_i $ 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.
输入格式
The first line of the input contains one integer $ q $ ( $ 1 \le q \le 100 $ ) — the number of queries. Then $ q $ queries follow.
The first line of the query contains one integer $ n $ ( $ 1 \le n \le 100) $ — the number of goods. The second line of the query contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 10^7 $ ), where $ a_i $ is the price of the $ i $ -th good.
输出格式
For each query, print the answer for it — 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.
样例 #1
样例输入 #1
3
5
1 2 3 4 5
3
1 2 2
4
1 1 1 1
样例输出 #1
3
2
1
水到爆炸啊啊啊
题目大意:给你 $n$ 个商品的成本,问以何种价格售出这些商品 (每件商品定价相同) 你的盈利最少 (可以不盈利) 这怕不是个睿智
既然如此我们只需要求一个数列的平均数并上取整就好了嘛
废话不多说,上代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, m;
scanf("
int sum = 0;
while (q--) {
scanf("
sum = 0;
int x;
for (int i = 1; i <= m; i++) {
scanf("
sum += x; //在读入的过程中计算总和
}
printf("
//输出平均数上取整(即大于等于平均数的最小整数)
}
return 0;
}
Comments NOTHING