洛谷 CF1234A Equalize Prices Again

洛谷传送门

题目描述

You are both a shop keeper and a shop assistant at a small nearby shop. You have nn goods, the ii -th good costs a_ia**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 nn 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 nn 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 nn 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 qq independent queries.

输入格式

The first line of the input contains one integer qq ( 1 \le q \le 1001≤q≤100 ) — the number of queries. Then qq queries follow.

The first line of the query contains one integer nn ( 1 \le n \le 100)1≤n≤100) — the number of goods. The second line of the query contains nn integers a_1, a_2, \dots, a_na1,a2,…,a**n ( 1 \le a_i \le 10^71≤a**i≤107 ), where a_ia**i is the price of the ii -th good.

输出格式

For each query, print the answer for it — the minimum possible equal price of all nn 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复制

题意翻译:

(版权来自巨佬@littleseven)

题解:

因为要把全部的商品赋上一个值,又想让这些值的和大于等于原来的数列和。要求维护这个答案最小,那么就一定是等于原来的数列和。

试想,假如钱可以有小数,那么这个答案一定是整个数列的平均值。

但是,因为不能有小数,而C++的除法运算又是向下取整。所以我们要在做完一次除法之后进行判断:如果的确是整除,那么直接输出商,否则要输出商加一。

这就是这道比较复杂的题(滑稽)的题解:

Code:

#include<cstdio>
#define ll long long
using namespace std;
ll t,sum,n;
int main()
{
scanf("%lld",&t);
while(t--)
{
sum=0;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
ll x;
scanf("%lld",&x);
sum+=x;
}
int t=sum/n;
if(t*n==sum)
printf("%d\n",t);
else
printf("%d\n",t+1);
}
return 0;
}

CF1234A Equalize Prices的更多相关文章

  1. 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 assistan ...

  2. Codeforcs 1183B Equalize Prices

    题目链接:codeforces.com/problemset/problem/1183/B 题意:给你 n 个数,每个数能在k范围内上下浮动,求能否使所有数相等,能输出相等的最大值,不能输出 -1. ...

  3. Codeforces Round #570 (Div. 3) B. Equalize Prices

    原文链接https://codeforces.com/contest/1183/problem/B 题意:进行Q组测试,在每组中有长度为n的数组a[i],然后现在给你一个K,问你找到一个bi使得|ai ...

  4. Codeforces Round #570 (Div. 3) B. Equalize Prices、C. Computer Game、D. Candy Box (easy version)、E. Subsequences (easy version)

    B题题意: 给你n个物品的价格,你需要找出来一个值b,使得每一个物品与这个b的差值的绝对值小于k.找到最大的b输出,如果找不到,那就输出-1 题解: 很简单嘛,找到上下限直接二分.下限就是所有物品中最 ...

  5. Eqaulize Prices

    There are n products in the shop. The price of the ii-th product is aiai. The owner of the shop want ...

  6. Codeforces Round #590 (Div. 3)

    A. Equalize Prices Again 题目链接:https://codeforces.com/contest/1234/problem/A 题意:给你 n 个数 , 你需要改变这些数使得这 ...

  7. Codeforces Round #590 (Div. 3)(e、f待补

    https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...

  8. Round #590 (Div. 3)

    拿DIV找快乐... 当场过了A-B1-B2-C 写D差5分钟写的是正解...留坑补FG A. Equalize Prices Again 直接判断sum%n==0?sum/n:sum/n+1 B1, ...

  9. Codeforces Round #590

    题目链接:Round #590 题目答案:官方Editorial.My Solution A. Equalize Prices Again 签到题还WA了一发,向上取整有点问题: //my wrong ...

随机推荐

  1. Paper | Model-blind video denoising via frame-to-frame training

    目录 故事 本文方法 流程 训练 实验 发表在2019年CVPR. 核心内容:基于Noise2Noise思想,这篇文章致力于无监督的视频盲去噪:是的,连噪声样本都不需要了. 这篇文章写作和概括太棒了! ...

  2. golang基础之第一个go程序

    编写 Hello World 创建文件 hello.go,不写入任何内容.按照如下的命令尝试进行编译 $ go run hello.go 将会打印出如下错误: package main: hello. ...

  3. consul实现kubernetes-1.15集群master的高可用访问实现

    1.准备consul环境,参考我之前的博客实现或参考consul的官网部署最新的consul. 2.本次测试使用的是kubernetes-1.15.0 3.初始化集群 1)准备初始化文件 contro ...

  4. springboot 使用 freemarker 无法正常跳转的问题?

    1.springboot 使用 freemarker 无法正常跳转的问题? 参考:https://blog.csdn.net/Lin_xiaofeng/article/details/79122053 ...

  5. SpringBoot2.x|Thymeleaf页面不能正常载入css、js文件

    1.实现实现WebMvcConfig配置类可以解决页面不能加载css,js的问题: 扩展SpringMvc,编写一个配置类(@Configuration),是WebMvcConfigurationAd ...

  6. .Net MVC 提示未能加载文件或程序集

    最近在开发.Net MVC程序时,突然出现未能加载文件或程序集的错误, 错误1 错误2 猜测时由于引用了Swagger,导致Swagger依赖的组件版本和现有版本冲突(现在仍未确定是这个原因),浪费了 ...

  7. 利用Java EE里jsp制作登录界面

    jsp连接数据库.百度经验. 1.在新建的Project中右键新建Floder 2.创建名为lib的包 3.创建完毕之后的工程目录 4.接下来解压你下载的mysql的jar包,拷贝其中的.jar文件 ...

  8. 如何搭建wordpress ,wecenter

    14.什么是LNMP架构 LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写.L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可 ...

  9. Unix/Linux/Mac os下 文件互传

    说起文件互传,就不得不提命令scp. 他是Secure copy的缩写,使用ssh连接和加密方式, 如果两台机器之间配置了ssh免密登录, 那在使用scp的时候可以不用输入密码.  scp 和 cp ...

  10. ES项目实战

    前置 ES: Java Spark/Flink Stack + Spring Boot + ES Scala/Java + Java/Scala + Java ==> 用API的方式来掌握ES的 ...