CF488B.Candy Boxes
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {_x_1, _x_2, _x_3, _x_4} (_x_1 ≤ _x_2 ≤ _x_3 ≤ _x_4) arithmetic mean is
, median is
and range is _x_4 - _x_1. The arithmetic mean and median are not necessary integer. It is well-known that if those three numbers are same, boxes will create a "debugging field" and codes in the field will have no bugs.
For example, 1, 1, 3, 3 is the example of 4 numbers meeting the condition because their mean, median and range are all equal to 2.
Jeff has 4 special boxes of candies. However, something bad has happened! Some of the boxes could have been lost and now there are only n (0 ≤ n ≤ 4) boxes remaining. The i-th remaining box contains a__i candies.
Now Jeff wants to know: is there a possible way to find the number of candies of the 4 - n missing boxes, meeting the condition above (the mean, median and range are equal)?
在 Cyberland,人们一直有在家里存放 4 盒糖果的传统。当这 4 盒糖果的数量满足其算术平均数、中位数与极差(最大值减最小值)三者全部相等时,这些数量就被称为“特殊的”。
根据定义,对于一个集合 {x1,x2,x3,x4}(其中 x1≤x2≤x3≤x4),其算术平均数为
,中位数为
,极差为 x4−x1。注意:算术平均数和中位数不一定是整数。众所周知,若这三个数值相等,则这四盒糖果将生成一个“调试场”(debugging field),处于该场内的代码将不会出现任何 bug。
例如,1,1,3,3 就是一组满足条件的 4 个数,因为它们的平均数、中位数与极差均为 2。
Jeff 拥有 4 盒这样的特殊糖果。然而,不幸的事情发生了!其中一些盒子可能已经丢失,现在仅剩下 n(0≤n≤4)盒。第 i 个剩余的盒子中含有 ai 颗糖果。
现在 Jeff 想知道:是否存在一种方式,为缺失的 4−n 盒糖果确定各自所含的糖果数量,使得全部 4 盒糖果的数量满足上述条件(即平均数、中位数与极差三者相等)?
输入格式
The first line of input contains an only integer n (0 ≤ n ≤ 4).
The next n lines contain integers a__i, denoting the number of candies in the i-th box (1 ≤ a__i ≤ 500).
输入的第一行包含一个整数 n(0 ≤ n ≤ 4)。
接下来的 n 行每行包含一个整数 ai,表示第 i 个盒子中的糖果数量(1 ≤ ai ≤ 500)。
输出格式
In the first output line, print "YES" if a solution exists, or print "NO" if there is no solution.
If a solution exists, you should output 4 - n more lines, each line containing an integer b, denoting the number of candies in a missing box.
All your numbers b must satisfy inequality 1 ≤ b ≤ 106. It is guaranteed that if there exists a positive integer solution, you can always find such b's meeting the condition. If there are multiple answers, you are allowed to print any of them.
Given numbers a__i may follow in any order in the input, not necessary in non-decreasing.
a__i may have stood at any positions in the original set, not necessary on lowest n first positions.
在第一行输出中,如果存在解,则输出“YES”;如果无解,则输出“NO”。
若存在解,你应再输出 4−n 行,每行包含一个整数 b,表示某个缺失盒子中的糖果数量。
所有你输出的数 b 必须满足不等式 1≤b≤106。题目保证:若存在正整数解,则总能找到满足该条件的 b。若存在多个答案,你可以输出其中任意一个。
输入中的给定数字 ai 可以以任意顺序出现,不一定按非递减顺序排列。
ai 在原始集合中可位于任意位置,不一定位于最前面的 n 个位置。
输入输出样例
输入#1
2 1 1
输出#1
YES 3 3
输入#2
3 1 1 1
输出#2
NO
输入#3
4 1 2 2 3
输出#3
YES
说明/提示
For the first sample, the numbers of candies in 4 boxes can be 1, 1, 3, 3. The arithmetic mean, the median and the range of them are all 2.
For the second sample, it's impossible to find the missing number of candies.
In the third example no box has been lost and numbers satisfy the condition.
You may output b in any order.
对于第一个样例,4 个盒子中的糖果数量可以是 1,1,3,3。它们的算术平均数、中位数和极差均为 2。
对于第二个样例,无法找到缺失的糖果数量。
在第三个样例中,没有盒子丢失,且数字满足条件。
你可以以任意顺序输出 b。
输入解题思路,AI测评打分。不知道怎么写?