Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- #define pb push_back
- #define eb emplace_back
- #define rsz resize
- #define all(a) a.begin(), a.end()
- template<class T> bool ckmax(T& a, T b){return a < b ? a = b, true : false;}
- template<class T> bool ckmin(T& a, T b){return a > b ? a = b, true : false;}
- using namespace std;
- using ll = long long;
- using ld = long double;
- using vi = vector<int>;
- using vll = vector<ll>;
- using pii = pair<int, int>;
- using vpii = vector<pair<int, int>>;
- using vpll = vector<pair<ll, ll>>;
- const int N = 1e6 + 5;
- const ll INF = 1e18;
- const ll LINF = 1e18;
- const int mod = 998244353;
- vector<ld> a(4), b(4);
- vi p(3);
- void operation(int type, int i, int j){
- if(type == 0)a[i] = a[j] = a[i] * a[j];
- if(type == 1)a[i] = a[j] = a[i] / a[j];
- if(type == 2)a[i] = a[j] = a[i] + a[j];
- if(type == 3)a[i] = a[j] = a[i] - a[j];
- }
- set<int> st;
- void solve(){
- ld eps = 1e-8;
- for(int i = 0; i < 4; ++i){
- for(int j = 0; j < 4; ++j){
- for(int q = 0; q < 4; ++q){
- for(int k = 0; k < 4; ++k)a[k] = b[k];
- operation(i, p[0] - 1, p[0]);
- operation(j, p[1] - 1, p[1]);
- operation(q, p[2] - 1, p[2]);
- // if(p[0] == 1 && p[2] == 2 && i == 1 && q == 1)cout << a[3] << < endl;
- a[3] = a[p[2]];
- if(a[3] - int(a[3]) < eps)st.insert(a[3]);
- }
- }
- }
- }
- int main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- for(auto &x:b)cin >> x;
- sort(all(b));
- p = {1, 2, 3};
- do{
- sort(all(p));
- do{
- solve();
- }while(next_permutation(all(p)));
- }while(next_permutation(all(b)));
- int ans = 0;
- for(auto x:st){
- // cout << x << " ";
- if(abs(ans - 21) > abs(x - 21)) ans = x;}
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement