-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbieu_thuc_toan_hoc.cpp
More file actions
62 lines (62 loc) · 1.24 KB
/
bieu_thuc_toan_hoc.cpp
File metadata and controls
62 lines (62 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
using namespace std;
bool ok;
vector<int> num(5);
int kq(int a,int b, char s){
if(s=='+') return a+b;
if(s=='-') return a-b;
return a*b;
}
bool cmp(vector<int> a,string s){
int m1=kq(a[0],a[1],s[0]);
int m2=kq(m1,a[2],s[1]);
int m3=kq(m2,a[3],s[2]);
int m4=kq(m3,a[4],s[3]);
return (m4==23);
}
void Try(string s,int i){
if(i==4){
if(cmp(num,s)){
ok =true;
}
return;
}
Try(s+"+",i+1);
Try(s+"-",i+1);
Try(s+"*",i+1);
}
vector<int> Init(vector<int> pos, vector<int> a){
vector<int>res;
for(int i=0;i<5;i++){
res.push_back(a[pos[i]-1]);
}
return res;
}
void slove(){
ok = false;
vector<int> a(5);
for(auto &i:a) cin >> i;
vector<int> pos(5);
for(int i=0;i<5;i++) pos[i]=i+1;
do{
num=Init(pos,a);
Try("",0);
} while(next_permutation(pos.begin(),pos.end()));
if(ok==true) cout << "YES\n";
else cout << "NO\n";
}
int main(){
int test=1;
cin >> test;
while(test--){
slove();
}
return 0;
}