| 23 | class Solution { |
| 24 | public: |
| 25 | bool judgePoint24(vector<int>& nums) { |
| 26 | for (int i = 0; i < 24; i ++ ) { |
| 27 | next_permutation(nums); |
| 28 | int x1 = nums[0], x2 = nums[1], x3 = nums[2], x4 = nums[3]; |
| 29 | // printf("%d %d %d %d\n", x1, x2, x3, x4); |
| 30 | for (Ops i = Add; i <= Div; i ++) { |
| 31 | for (Ops j = Add; j <= Div; j ++) { |
| 32 | for (Ops k = Add; k <= Div; k ++) { |
| 33 | // if (x1 == 6 and x2 == 1 and x3 == 3 and x4 == 4 and |
| 34 | // i == Div and j == Minus and k == Div) { |
| 35 | // cout << to_str(i) << to_str(j) << to_str(k) << endl; |
| 36 | // cout << abs(oper(i, oper(j, oper(k, x3, x4), x2), x1)) << endl; |
| 37 | // } |
| 38 | |
| 39 | if (1e-5 > abs(oper(k, oper(j, oper(i, x1, x2), x3), x4) - 24) || |
| 40 | 1e-5 > abs(oper(j, oper(i, x1, x2), oper(k, x3, x4)) - 24) || |
| 41 | 1e-5 > abs(oper(i, x1, oper(k, oper(j, x2, x3), x4)) - 24) || |
| 42 | 1e-5 > abs(oper(i, x1, oper(j, x2, oper(k, x3, x4))) - 24) ) |
| 43 | return true; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | double oper(Ops op, double x, double y) { |
| 52 | switch (op) { |