Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define F first
  4. #define S second
  5. #define pb push_back
  6. #define eb emplace_back
  7. #define rsz resize
  8. #define all(a) a.begin(), a.end()
  9.  
  10. template<class T> bool ckmax(T& a, T b){return a < b ? a = b, true : false;}
  11. template<class T> bool ckmin(T& a, T b){return a > b ? a = b, true : false;}
  12.  
  13. using namespace std;
  14. using ll = long long;
  15. using ld = long double;
  16. using vi = vector<int>;
  17. using vll = vector<ll>;
  18. using pii = pair<int, int>;
  19. using vpii = vector<pair<int, int>>;
  20. using vpll = vector<pair<ll, ll>>;
  21.  
  22. const int N = 1e6 + 5;
  23. const ll INF = 1e18;
  24. const ll LINF = 1e18;
  25. const int mod = 998244353;
  26.  
  27. vector<ld> a(4), b(4);
  28. vi p(3);
  29.  
  30. void operation(int type, int i, int j){
  31.     if(type == 0)a[i] = a[j] = a[i] * a[j];
  32.     if(type == 1)a[i] = a[j] = a[i] / a[j];
  33.     if(type == 2)a[i] = a[j] = a[i] + a[j];
  34.     if(type == 3)a[i] = a[j] = a[i] - a[j];
  35. }
  36.  
  37. set<int> st;
  38.  
  39. void solve(){
  40.     ld eps = 1e-8;
  41.     for(int i = 0; i < 4; ++i){
  42.         for(int j = 0; j < 4; ++j){
  43.             for(int q = 0; q < 4; ++q){
  44.                 for(int k = 0; k < 4; ++k)a[k] = b[k];
  45.                 operation(i, p[0] - 1, p[0]);
  46.                 operation(j, p[1] - 1, p[1]);
  47.                 operation(q, p[2] - 1, p[2]);
  48.                // if(p[0] == 1 && p[2] == 2 && i == 1 && q == 1)cout << a[3] << < endl;
  49.                 a[3] = a[p[2]];
  50.                 if(a[3] - int(a[3]) < eps)st.insert(a[3]);
  51.             }
  52.         }
  53.     }
  54. }
  55.  
  56. int main(){
  57.     ios_base::sync_with_stdio(0); cin.tie(0);
  58.     for(auto &x:b)cin >> x;
  59.     sort(all(b));
  60.     p = {1, 2, 3};
  61.     do{
  62.         sort(all(p));
  63.         do{
  64.              solve();
  65.         }while(next_permutation(all(p)));
  66.     }while(next_permutation(all(b)));
  67.     int ans = 0;
  68.     for(auto x:st){
  69.        // cout << x << " ";
  70.         if(abs(ans - 21) > abs(x - 21)) ans = x;}
  71.     cout << ans;
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement