洛谷 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:

  1. #include<cstdio>
  2. #define ll long long
  3. using namespace std;
  4. ll t,sum,n;
  5. int main()
  6. {
  7. scanf("%lld",&t);
  8. while(t--)
  9. {
  10. sum=0;
  11. scanf("%lld",&n);
  12. for(int i=1;i<=n;i++)
  13. {
  14. ll x;
  15. scanf("%lld",&x);
  16. sum+=x;
  17. }
  18. int t=sum/n;
  19. if(t*n==sum)
  20. printf("%d\n",t);
  21. else
  22. printf("%d\n",t+1);
  23. }
  24. return 0;
  25. }

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. 【java】svn显示&#215;

    背景:将客服系统代码赋值到商户子系统中,复制过去后,所有代码svn显示×. 可能:代码直接复制过去只是表面上再maven中显示的代码复制过去,不是真的代码,所以对于svn来讲真的代码删了,又来了一堆新 ...

  2. P2P中的NAT穿越(打洞)方案详解

    一.P2P(点对点技术) 点对点技术(peer-to-peer,简称P2P)又称对等互联网络技术,是一种网络新技术,依赖网络中参与者的计算能力和带宽,而不是把依赖都聚集在较少的几台服务器上. 点对点技 ...

  3. [LOJ 6432][PKUSC 2018]真实排名

    [LOJ 6432][PKUSC 2018]真实排名 题意 给定 \(n\) 个选手的成绩, 选中其中 \(k\) 个使他们的成绩翻倍. 对于每个选手回答有多少种方案使得他的排名不发生变化. \(n\ ...

  4. Luogu P4341 [BJWC2010]外星联络

    题目描述 暴力思路: 暴力枚举子串,插入trie树中,按字典序输出大于1的end的值 时间复杂度:n3 结果:TLE 0分 ...非常尴尬的一点不剩 正解思路 经过观察发现,可以只枚举后缀,统计时输出 ...

  5. python运维开发常用模块(6)发送电子邮件模块smtplib

    1.模块常用方法 SMTP类定义:smtplib.SMTP([host[,port[,local_hostname[, timeout]]]]),作为SMTP的构造函数,功能是与smtp服务器建立连接 ...

  6. HBase开发错误记录(java.net.UnknownHostException: unknown host: hadoop111)

    windows下开发HBase应用程序,HBase部署在linux环境中, 在运行调试时可能会出现无法找到主机,类似异常信息如下: java.net.UnknownHostException: unk ...

  7. RoadMap:如何创建产品路线图

    (1)什么是Roadmap? RoadMap/产品路线图 Roadmap通常翻译为“路线图”或“蓝图”,目前并没有一个公认的定义.在这里,我们认为Roadmap是产品经理进行产品管理的一个中长期规划, ...

  8. 【Zabbix】zabora监控Oracle数据库

    zabora监控Oracle数据库 它作为一个开源项目,通过shell脚本有效的监控Oracle基础指标.本文档旨在通过实战,在Zabbix 3.0版本之下,监控生产环境下的多台Oracle数据库. ...

  9. 架构设计系列-前端模式的后端(BFF)翻译PhilCalçado

    本文翻译自PhilCalçado的官网:https://philcalcado.com/2015/09/18/the_back_end_for_front_end_pattern_bff.html 对 ...

  10. 北京麒麟会GITC

    分享ppt:https://pan.baidu.com/s/1Aerqtbi8VpMiFGhfEMUtPQ http://bj.thegitc.com/#meeting-agenda