CF1234A Equalize Prices
洛谷 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的更多相关文章
- 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 ...
- Codeforcs 1183B Equalize Prices
题目链接:codeforces.com/problemset/problem/1183/B 题意:给你 n 个数,每个数能在k范围内上下浮动,求能否使所有数相等,能输出相等的最大值,不能输出 -1. ...
- Codeforces Round #570 (Div. 3) B. Equalize Prices
原文链接https://codeforces.com/contest/1183/problem/B 题意:进行Q组测试,在每组中有长度为n的数组a[i],然后现在给你一个K,问你找到一个bi使得|ai ...
- 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 题解: 很简单嘛,找到上下限直接二分.下限就是所有物品中最 ...
- Eqaulize Prices
There are n products in the shop. The price of the ii-th product is aiai. The owner of the shop want ...
- Codeforces Round #590 (Div. 3)
A. Equalize Prices Again 题目链接:https://codeforces.com/contest/1234/problem/A 题意:给你 n 个数 , 你需要改变这些数使得这 ...
- Codeforces Round #590 (Div. 3)(e、f待补
https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...
- 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, ...
- Codeforces Round #590
题目链接:Round #590 题目答案:官方Editorial.My Solution A. Equalize Prices Again 签到题还WA了一发,向上取整有点问题: //my wrong ...
随机推荐
- react中使用动画
1. css原生动画的使用 import React, { useState } from "react" import "./index.css" funct ...
- Shell编程——运算符
1.declare命令: 声明变量的类型: -:给变量设定类型属性 +:给变量取消类型属性 -i:将变量声明为整数类型 -x:将变量声明为环境变量 -p:显示变量的类型 其中export是将num变为 ...
- 开发者必备Linux命令
开发者必备Linux常用命令,掌握这些命令绝对够了,基于CenterOS7.6. 系统服务管理 systemctl 输出系统中各个服务的状态: systemctl list-units --type= ...
- 【转】java MessageDigest类的作用 :提供信息摘要 算法( MD5 或 SHA 等)的功能
一.结构和概述: java.lang.Object java.security.MessageDigestSpi java.security.MessageDigest 声明:public abstr ...
- Xshell删除键不好使:删除显示退格^H
Xshell删除键不好使:删除显示退格^H 1.问题: Xshell不能删除,删除时出现 退格^H 2.解决方案: 点击上方:文件→属性→终端→键盘,把 delete 和 backspace 序列改为 ...
- HTTP协议第一篇:三握手解读
TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 位码即tcp标志位,有6种标 ...
- MySQL如果频繁的修改一个表的数据,那么这么表会被锁死。造成假死现象。
MySQL如果频繁的修改一个表的数据,那么这么表会被锁死.造成假死现象. 比如用Navicat等连接工具操作,Navicat会直接未响应,只能强制关闭软件,但是重启后依然无效. 解决办法: 首先执行: ...
- mybatis批处理数据
批处理数据主要有三种方式: 1.传统jdbc处理 2.mybatis批处理插入 3.使用executortype处理 jdbc 处理 1.通过 for循环插入 main方法如下所示: Co ...
- mysql8 安装
准备工作: 首先安装这些依赖 yum install -y flex yum install gcc gcc-c++ cmake ncurses ncurses-devel bison libaio ...
- WPF-数据模板深入(加载XML类型数据)
一.我们知道WPF数据模板是当我们给定一个数据类型,我们为这个数据类型写好布局,就给这种数据类型穿上了外衣. 下面这个例子,能够帮助大家充分理解数据模板就是数据类型的外衣的意思:(里面的MyListB ...