Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <stack>
  5. #include <queue>
  6. #include <iomanip>
  7. #include <fstream>
  8. #include <set>
  9. #include <sstream>
  10. #include <map>
  11. #include <limits>
  12. #include <bitset>
  13. #include <memory.h>
  14. #include <string>
  15.  
  16. using namespace std;
  17. typedef long long ll;
  18. typedef long double ld;
  19. typedef pair<ll,ll> pii;
  20. #define REP(i, n) for (ll i = 0; i < n; i++)
  21. #define MN(a, b) a = min(a, b)
  22. #define MX(a, b) a = max(a, b)
  23.  
  24. using namespace std;
  25.  
  26. bool check(ll x1, ll x2, ll x3, ll x4)
  27. {
  28.     bool ok = true;
  29.         ok &= (x1 >= 1 && x1 <= 1000000);
  30.         ok &= (x2 >= 1 && x2 <= 1000000);
  31.         ok &= (x3 >= 1 && x3 <= 1000000);
  32.         ok &= (x4 >= 1 && x4 <= 1000000);
  33.         ok &= (x1 + x2 + x3 + x4) == 2*(x2+x3);
  34.         ok &= 2*(x2+x3) == 4*(x4-x1);
  35.     return ok;
  36. }
  37.  
  38. bool check2(ll x1, ll x2, ll x3, ll x4)
  39. {
  40.     bool ok = true;
  41.         ok &= (4*x1 - x2) == x3;
  42.         ok &= (3*x1) == x4;
  43.         ok &= check(x1,x2,x3,x4);
  44.         ok &= (x1 <= x2);
  45.         ok &= (x2 <= x3);
  46.         ok &= (x3 <= x4);
  47.     return ok;
  48. }
  49.  
  50. int main()
  51. {
  52.     ios_base::sync_with_stdio(false);
  53.  
  54.     bool ok = true;
  55.  
  56.     ll n;
  57.     cin >> n;
  58.     if (n == 4)
  59.     {
  60.         ll x1,x2,x3,x4;
  61.         cin >> x1 >> x2 >> x3 >> x4;
  62.         ok &= check2(x1,x2,x3,x4);
  63.         if (ok) cout << "YES" << endl;
  64.         else cout << "NO" << endl;
  65.     }
  66.     else if (n == 3)
  67.     {
  68.         ll x1,x2,x3,x4;
  69.         cin >> x1 >> x2 >> x3;
  70.         x4 = (x2+x3)/2 + x1;
  71.         ok &= (x2+x3)%2 == 0;
  72.         ok &= check2(x1,x2,x3,x4);
  73.         if (ok) cout << "YES" << endl << x4 << endl;
  74.         else cout << "NO" << endl;
  75.     }
  76.     else if (n == 2)
  77.     {
  78.         ll x1,x2,x3,x4;
  79.         cin >> x1 >> x2;
  80.         x3 = 4*x1 - x2;
  81.         x4 = 3*x1;
  82.         if (x3 > x4) swap(x3,x4);
  83.         ok &= check2(x1,x2,x3,x4);
  84.         if (ok) cout << "YES" << endl << x3 << endl << x4 << endl;
  85.         else cout << "NO" << endl;
  86.     }
  87.     else if (n == 1)
  88.     {
  89.         ll x1,x2,x3,x4;
  90.         cin >> x1;
  91.         x2 = x1;
  92.         x3 = 4*x1 - x2;
  93.         x4 = 3*x1;
  94.         if (x2 > x3) swap(x2, x3);
  95.         if (x2 > x4) swap(x2, x4);
  96.         if (x3 > x4) swap(x3, x4);
  97.         ok &= check2(x1,x2,x3,x4);
  98.         if (ok) cout << "YES" << endl << x2 << endl << x3 << endl << x4 << endl;
  99.         else cout << "NO" << endl;
  100.     }
  101.     else if (n == 0)
  102.     {
  103.         ll x1, x2, x3, x4;
  104.         x1 = 1;
  105.         x2 = 1;
  106.         x3 = 4*x1 - x2;
  107.         x4 = 3*x1;
  108.         ok &= check2(x1,x2,x3,x4);
  109.         if (ok) cout << "YES" << endl << x1 << endl << x2 << endl << x3 << endl << x4 << endl;
  110.         else cout << "NO" << endl;
  111.     }
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement