// 唉,写得真TM丑
#include <iostream>
#include <cmath>
using namespace std;
bool calcu_2(double a, double b)
{
if(fabs(a + b - 24) < 1e-6
|| fabs(a - b - 24) < 1e-6
|| fabs(b - a - 24) < 1e-6
|| fabs(a * b -24) < 1e-6
|| fabs(a / b - 24) < 1e-6
|| fabs(b / a - 24) < 1e-6)
return true;
else return false;
}
bool calcu_3(double a, double b, double c)
{
if(
calcu_2((a + b), c) || calcu_2((a - b), c) || calcu_2((b - a), c) ||
calcu_2((a * b), c) || calcu_2((a / b), c) || calcu_2((b / a), c) ||
calcu_2((a + c), b) || calcu_2((a - c), b) || calcu_2((c - a), b) ||
calcu_2((a * c), b) || calcu_2((a / c), b) || calcu_2((c / a), b) ||
calcu_2((b + c), a) || calcu_2((b - c), a) || calcu_2((c - b), a) ||
calcu_2((b * c), a) || calcu_2((b / c), a) || calcu_2((c / b), a))
return true;
else return false;
}
bool calcu_4(double a, double b, double c, double d)
{
if(calcu_3(a+b,c,d) || calcu_3(a*b,c,d) || (calcu_3(b/a,c,d)) || calcu_3(b-a,c,d) || (calcu_3(a/b,c,d)) || calcu_3(a-b,c,d) )
return true;
else return false;
}
int num[4] = {};
int main()
{
while(cin >> num[0] >> num[1] >> num[2] >> num[3])
{
if(num[0] == 0 && num[1] == 0 && num[2] == 0 && num[3] == 0)
return 0;
double a, b, c, d;
int ok = 0;
int use[4] = {0};
for(int i = 0; i < 4; i++)
{
if(!use[i])
{
use[i] = 1;
a = num[i];
for(int j = 0; j < 4; j++)
{
if(!use[j])
{
use[j] = 1;
b = num[j];
for(int k = 0; k < 4; k++)
{
if(!use[k])
{
use[k] = 1;
c = num[k];
for(int l = 0; l < 4; l++)
{
if(!use[l])
{
use[l] = 1;
d = num[l];
if(calcu_4(a, b, c, d))
ok = 1;
else use[l] = 0;
}
}
if(!ok)
use[k] = 0;
}
}
if(!ok)
use[j] = 0;
}
}
if(!ok)
use[i] = 0;
}
}
if(ok)
cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
算24
最新推荐文章于 2018-12-08 11:19:00 发布