讨论 / AC,第一题
zhu1650465459 2015-08-01 19:04:06
点我顶贴 收藏 删除
#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

int f[5]={0},num=0,a[5];

string c;

int pai[5];

bool used[5];

bool dfs1(int dep,double unt)

{

if(dep==4)

{

if(unt>23.999999 && unt<24.000001) return true;

else return false;

}

else

{

for(int i=0;i<4;i++)

if(!used[i])

{

used[i]=true;

if(dfs1( dep+1,unt+pai[i]) ) return true;

if(dfs1( dep+1,unt-pai[i]) ) return true;

if(dfs1( dep+1,pai[i]-unt) ) return true;

if( unt!=0 && dfs1(dep+1,unt*pai[i]) ) return true;

if( unt!=0 && dfs1(dep+1,unt/pai[i]) ) return true;

if( unt!=0 && dfs1(dep+1,pai[i]/unt) ) return true;

used[i]=false;

}

return false;

}

}

int main()

{

for(int i=0;i<=3;i++)

{

cin>>c;

if(c[0]=='A')

pai[i]=1;

else if(c[0]=='J')

pai[i]=11;

else if(c[0]=='Q')

pai[i]=12;

else if(c[0]=='K')

pai[i]=13;

else if(c[0]=='1' && c[1]=='0')

pai[i]=10;

else

pai[i]=c[0]-'0';

}

if(dfs1(0,0))

printf("yes\n");

else

printf("no\n");

return 0;

}

查看更多回复
提交回复