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

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 ;
}

Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]的更多相关文章

  1. codeforces水题100道 第二十题 Codeforces Round #191 (Div. 2) A. Flipping Game (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/327/A题意:你现在有n张牌,这些派一面是0,另一面是1.编号从1到n,你需要翻转[i,j]区间的 ...

  2. codeforces水题100道 第十九题 Codeforces Round #109 (Div. 2) A. I_love_%username% (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/155/A题意:找到当前最大值或者最小值出现的次数.“当前”的意思差不多是a[i]大于所有a[j]( ...

  3. codeforces水题100道 第十三题 Codeforces Round #166 (Div. 2) A. Beautiful Year (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/271/A题意:给你一个四位数,求比这个数大的最小的满足四个位的数字不同的四位数.C++代码: #i ...

  4. Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)

    B. Candy Boxes Problem's Link:   http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...

  5. Codeforces Round #278 (Div. 2)

    题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...

  6. Codeforces Round #278 (Div. 1) B. Strip multiset维护DP

    B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...

  7. Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力

    A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...

  8. CodeForces Round #278 (Div.2) (待续)

    A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...

  9. Codeforces Round #278 (Div. 1)

    A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...

随机推荐

  1. sort函数的使用

    此篇当作自己的笔记(水平太菜,这都一直没搞明白) sort()函数的用法1)sort函数包含在头文件<algroithm>中,还要结合using namespace std2)sort有三 ...

  2. Web开发者必须知道的10个jQuery代码片段

    在过去的几年中,jQuery一直是使用最为广泛的JavaScript脚本库.今天我们将为各位Web开发者提供10个最实用的jQuery代码片段,有需要的开发者可以保存起来. 1.检测Internet ...

  3. Python基础篇 -- 列表

    3.2 列表的增删改查 ​ 列表使用 [] 来表示,列表中每个元素与元素之间用逗号隔开 ​ 列表也有索引和切片 # 切片切出来的也是列表 lst = ["梅西", "内马 ...

  4. vue表单验证:vee-validate中文提示

    官方文档:https://baianat.github.io/vee-validate/guide/ vee-validate可用于vue项目中进行表单验证,使用方法在官方API上都可以查到: 使用过 ...

  5. Fortran学习笔记4(循环语句)

    Fortran学习笔记4 Fortran学习笔记4 逻辑运算 循环 Do语句 Do-While循环 循环控制 循环应用实例 逻辑运算 if命令需要和逻辑运算表达式搭配才能起到很好的效果.下面分别列出F ...

  6. scrollTop如何实现click后页面过渡滚动到顶部

    用JS操作,body元素的scrollTop var getTop = document.getElementById("get-top"); var head = documen ...

  7. perl学习之:正则表达式

  8. python--MySQl单表查询

    一.  关键字的执行优先级(重点) from where group by having # 使用是要放在group by 后面而且前面必须有group by select distinct # 去重 ...

  9. 常用模块之configpaser与shutil

    configparser模块 定义:configparser翻译为配置解析,即它是用来解析配置文件的 配置文件:用于编写程序的配置信息的文件 配置文件编写格式 配置文件中只允许出现两种类型的数据 se ...

  10. solr DIH 设置定时索引

    1 web.xml中加入 web.xml所在目录 /opt/solr-7.7.1/server/solr-webapp/webapp/WEB-INF <listener> <list ...