Codeforces Round #278 (Div. 2)B?? Candy Boxes_html/css_WEB-ITnose
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 <= n; ++i) { scanf("%d", &a[i]); } sort(a + 1, a + n + 1); if (n == 4) { double u = (a[1] + a[2] + a[3] + a[4]) * 1.0; u /= 4; double v = (a[4] - a[1]); double w = (a[2] + a[3]) * 1.0 / 2; if (u != v || u != w || v != w) { printf("NO\n"); } else { printf("YES\n"); } continue; } else if(n == 3) { int u = (a[2] + a[3] - a[1]); bool flag = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; int p = u + a[1] + a[2] + a[3]; int q = u - a[1]; int r = a[2] + a[3]; if (p % 4 || r % 2) { flag = true; } else { p /= 4; r /= 2; } if (!flag && (p != q || p != r || q != r)) { flag = true; } if (!flag && u >= 1 && u <= 1000000 && 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 <= 1000000 && u >= a[2] && u <= a[3]) { printf("YES\n"); printf("%d\n", u); continue; } u = a[1] + a[3] - a[2]; p = u + a[1] + a[2] + a[3]; q = a[3] - a[1]; r = (u + a[2]); if (p % 4 || r % 2) { flag3 = true; } else { p /= 4; r /= 2; } if (!flag3 && (p != q || p != r || q != r)) { flag3 = true; } if (!flag3 && u >= 1 && u <= 1000000 && u >= a[1] && u <= a[2]) { 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] - u; r = a[1] + a[2]; if (p % 4 || r % 2) { flag4 = true; } else { p /= 4; r /= 2; } if (!flag4 && (p != q || p != r || q != r)) { flag4 = true; } if (!flag4 && u >= 1 && u <= 1000000 && u <= a[1]) { printf("YES\n"); printf("%d\n", u); continue; } if (flag && flag2 &&flag3 && flag4) { printf("NO\n"); } } else if(n == 1) { int x4 = 3 * a[1]; int x23 = x4 + a[1]; int x2, x3; x2 = x3 = x23 / 2; if (a[1] <= x2 && x2 <= x3 && x3 <= x4) { printf("YES\n"); printf("%d\n%d\n%d\n", x2, x3, x4); } else { printf("NO\n"); } } else if ( n == 2) { int x1 = a[1], x2 = a[2]; int x4 = 3 * a[1]; int x3 = 4 * x1 - x2; if (x1 <= x2 && x2 <= x3 && x3 <= x4) { printf("YES\n"); printf("%d\n%d\n", x3, x4); continue; } x1 = a[1]; x3 = a[2]; x4 = 3 * a[1]; x2 = 4 * x1 - x3; if (x1 <= x2 && x2 <= x3 && x3 <= x4) { printf("YES\n"); printf("%d\n%d\n", x2, x4); continue; } bool flag = false; x2 = a[1]; x3 = a[2]; x1 = x2 + x3; if (x1 % 4) { flag = true; } else { x1 /= 4; x4 = 3 * x1; if (x1 <= x2 && x2 <= x3 && x3 <= x4) { printf("YES\n"); printf("%d\n%d\n", x1, x4); continue; } else { flag = true; } } bool flag2 = false; x2 = a[1]; x4 = a[2]; x1 = x4; if (x1 % 3) { flag2 = true; } else { x3 = x1 + x4 - x2; if (x1 <= x2 && x2 <= x3 && x3 <= x4) { printf("YES\n"); printf("%d\n%d\n", x1, x3); continue; } else { flag2 = true; } } bool flag3 = false; x3 = a[1]; x4 = a[2]; x1 = x4; x2 = x1 + x4 - x3; if (x1 % 3) { flag3 = true; } else { if (x1 <= x2 && x2 <= x3 && x3 <= x4) { printf("YES\n"); printf("%d\n%d\n", x1, x2); continue; } else { flag3 = true; } } if (flag && flag2 && flag3) { printf("NO\n"); } } else { printf("YES\n"); printf("1\n1\n3\n3\n"); } } return 0;}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.
