#include <iostream>
#include <cmath>
using namespace std;
const int R=24;
const double E=0.000001;
bool ishege(double a,int d)
{
if((fabs(a+d-R)<E)||(fabs(a-d-R)<E)||(fabs(d-a-R)<E)||(fabs(a*d-R)<E)||(fabs(a/d-R)<E)||(fabs(d/a-R)<E))
return true;
return false;
}
bool ishege(double da,int c,int d)
{
double db=c;
double r1=da/db;
double r2=db/da;
double r3=da-db;
double r4=db-da;
double r5=da+db;
double r6=da*db;
if(ishege(r1,d)||ishege(r2,d)||ishege(r3,d)||ishege(r4,d)||ishege(r5,d)||ishege(r6,d))
return true;
return false;
}
bool ishege(int a,int b,int c,int d)
{
double da=a;
double db=b;
double r1=da/db;
double r2=db/da;
double r3=da-db;
double r4=db-da;
double r5=da+db;
double r6=da*db;
if(ishege(r1,c,d)||ishege(r2,c,d)||ishege(r3,c,d)||ishege(r4,c,d)||ishege(r5,c,d)||ishege(r6,c,d))
return true;
return false;
}
int main()
{
int a,b,c,d;
while(cin>>a>>b>>c>>d)
{
if(ishege(a,b,c,d)||ishege(a,c,b,d)||ishege(a,d,c,b)||ishege(c,b,a,d)||ishege(d,b,c,a)||ishege(c,d,a,b))
cout << "true" << endl;
else
cout << "false" << endl;
}
return 0;
}
这道题目很有意思!!!
可惜我没有想到方便的做法。。。