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

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. Spring Boot配置文件大全

    Spring Boot配置文件大全 ############################################################# # mvc ############## ...

  2. Asp.Net Core 入门(七)—— 安装Bootstrap

    我们使用 libman包管理器来安装,libman是微软推出的最新的包管理器,它是一个轻量级的客户端管理工具,可以从CDN下载客户端库和框架,它要求VS Studio必须在2017版本15.8或更高版 ...

  3. Difference between x:Reference and x:Name

    {x:Reference ...} -> returns just a reference of an object it doesn't create that "bridge&qu ...

  4. Java中的线程--线程中的工具

    这主要想写一下Java中的jdk提供的一些线程中的工具, 一.semaphore信号灯 Semaphore可以维护当前访问自身的线程个数,并提供了同步机制,使用Semaphore可以控制同时访问资源的 ...

  5. Eclipse调试:项目在Debug模式下,无法启动的问题

    问题:Eclipse中调试Java项目时,使用正常模式:Run 项目名,可以正常启动.当想打断点调试时,点击Debug按钮后,项目显示 Source not found,或者弹出窗口显示服务器在45秒 ...

  6. ios坐标系统

    在写程序的时候发现,iOS下的坐标.位置很容易弄乱,特别是在不同的坐标系统中,必须完成弄明白一些概念才能做相应的变化,例如CoreImage和UIView的坐标系统就截然不同,一个是以屏幕的左上角为原 ...

  7. UVa 167(八皇后)、POJ2258 The Settlers of Catan——记两个简单回溯搜索

    UVa 167 题意:八行八列的棋盘每行每列都要有一个皇后,每个对角线上最多放一个皇后,让你放八个,使摆放位置上的数字加起来最大. 参考:https://blog.csdn.net/xiaoxiede ...

  8. NOIP 模拟题

    目录 T1 : grid T2 : ling T3 : threebody 数据可私信我. T1 : grid 题目:在一个\(n*n\)的方格中,你只能斜着走.为了让问题更简单,你还有一次上下左右走 ...

  9. 【动态规划】bzoj1044: [HAOI2008]木棍分割

    需要滚动优化或者short int卡空间 Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍 ...

  10. golang 实现冒泡排序

    package main import ( "fmt" ) func main(){ a := [...] int{2,5,9,6,8} fmt.Println(a) num := ...