> 웹 프론트엔드 > HTML 튜토리얼 > Codeforces Round #278 (Div. 2)B?? Candy Boxes_html/css_WEB-ITnose

Codeforces Round #278 (Div. 2)B?? Candy Boxes_html/css_WEB-ITnose

WBOY
풀어 주다: 2016-06-24 11:53:37
원래의
1320명이 탐색했습니다.

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

211
로그인 후 복사

Output

YES33
로그인 후 복사

Input

3111
로그인 후 복사

Output

NO
로그인 후 복사

Input

41223
로그인 후 복사

Output

YES
로그인 후 복사
 

很麻烦的一题啊,需要分别考虑0,1,2,3,4个数的情况

#include <map>#include <set>#include <list>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int a[5];int main(){	int n;	while (~scanf("%d", &n))	{		for (int i = 1; i = 1 && u = a[3])			{				printf("YES\n");				printf("%d\n", u);				continue;			}			u = a[1] + a[2] - a[3];			p = u + a[1] + a[2] + a[3];			q = a[3] - a[1];			r = (u + a[2]);			if (p % 4 || r % 2)			{				flag2 = true;			}			else			{				p /= 4;				r /= 2;			}			if (!flag2 && (p != q || p != r || q != r))			{				flag2 = true;			}			if (!flag2 && u >= 1 && u = a[2] && u = 1 && u = a[1] && u = 1 && u      <br>     <br>          </algorithm></iostream></cstring></cstdio></cmath></vector></stack></queue></list></set></map>
로그인 후 복사
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿