哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况

8795058                 2014-11-22 06:52:58     njczy2010     B - Candy Boxes             GNU C++     Accepted 31 ms 4 KB
8795016                 2014-11-22 06:48:15     njczy2010     B - Candy Boxes             GNU C++     Wrong answer on test 13                 30 ms                 0 KB    
8795000                 2014-11-22 06:44:39     njczy2010     B - Candy Boxes             GNU C++     Wrong answer on test 5                 15 ms                 0 KB
B. Candy Boxes
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 {x1, x2, x3, x4} (x1 ≤ x2 ≤ x3 ≤ x4) arithmetic mean is , median is and range is x4 - x1. 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 ai 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)?

Input

The first line of input contains an only integer n (0 ≤ n ≤ 4).

The next n lines contain integers ai, denoting the number of candies in the i-th box (1 ≤ ai ≤ 500).

Output

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 ai may follow in any order in the input, not necessary in non-decreasing.

ai may have stood at any positions in the original set, not necessary on lowest n first positions.

Sample test(s)
Input
2 1 1
Output
YES 3 3
Input
3 1 1 1
Output
NO
Input
4 1 2 2 3
Output
YES
Note

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.

主要就是根据那三个等式,化简,得两个方程:

x4=3*x1;

x2+x3=4*x1;

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<string>
//#include<pair> #define N 10005
#define M 1005
#define mod 1000000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-9
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int n;
int a[];
int b[];
int flag; void ini()
{
flag=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+,a++n);
} void solve0()
{
flag=;
b[]=;b[]=;b[]=;b[]=;
} void solve1()
{
flag=;
b[]=a[];b[]=*a[];b[]=*a[];
} void solve2()
{
if(a[]%==){
if(a[]/==a[]){
flag=;
b[]=a[];b[]=a[];
}
else if(a[]/<a[]){
flag=;b[]=a[]/;b[]=a[]+b[]-a[];
}
else{
return;
}
}
else{
if(a[]*<=a[]){
return;
}
else{
flag=;
b[]=a[]*;
b[]=b[]+a[]-a[];
}
}
} void solve3()
{
if(a[]%!=){
if(a[]*<=a[]){
return;
}
else{
if(a[]*==a[]+a[]){
flag=;b[]=a[]*;
}
else return;
}
}
else{
if(a[]/==a[]){
flag=;
b[]=a[]+a[]-a[];
}
else if(a[]/<a[]){
b[]=a[]/;
if(b[]+a[]==a[]+a[]){
flag=;
}
else return;
}
else{
return;
}
}
} void solve4()
{
if(a[]==*a[] && a[]+a[]==*a[]){
flag=;
}
} void solve()
{
if(n==){
solve4();
}
else if(n==){
solve0();
}
else if(n==){
solve1();
}
else if(n==){
solve2();
}
else if(n==){
solve3();
}
} void out()
{
int i;
if(flag==){
printf("YES\n");
for(i=;i<=-n;i++){
printf("%d\n",b[i]);
}
}
else{
printf("NO\n");
}
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
// while(T--)
while(scanf("%d",&n)!=EOF)
{
// if(n==0 && m==0 ) break;
//printf("Case %d: ",ccnt);
ini();
solve();
out();
} return ;
}

最新文章

  1. instanceof 运算符
  2. 【CodeVS2800】 送外卖 最短路+状压DP
  3. 通过数据库查看EBS的登录地址
  4. Linux学习心得之 jnlp的文件和java应用程序安全设置
  5. 使用GDataXML解析XML文档
  6. Matlab read_grib.r4 安装新方法(转自:http://blog.sina.com.cn/s/blog_9f36648b010179s7.html)
  7. bzoj 3669: [Noi2014]魔法森林 动态树
  8. chroot 的用途
  9. HTTP库Axios
  10. C博客作业01--分支,顺序结构
  11. [BZOJ4005][JLOI2015]骗我呢-[dp+容斥]
  12. spring学习总结(一)_Ioc基础(中)
  13. 2017-2018-2 20165236 实验三《Java面向对象程序设计》实验报告
  14. bootstrap1相关学习文档
  15. 微信小程序开发-滑动操作
  16. 从Web抓取信息的几个常用方法
  17. implicit declaration of function &#39;copy_from_user&#39;
  18. 设置zookeeper开机自启动
  19. Partial关键字
  20. Linux之(tomcat)服务之服务调优

热门文章

  1. 快学UiAutomator配置编辑环境
  2. SpringBoot入门,新建SpringBoot项目
  3. java中regex参考
  4. shell脚本,锁机制
  5. UIViewAnimationOptions
  6. APIO2019&amp;&amp;THUSC2019游记
  7. BIOM Table-codes
  8. Makefile文件中的sed介绍
  9. Java基础知识:集合框架
  10. 六丶人生苦短,我用python【第六篇】