s:string;
begin
readln (s);
if (copy (s,1,3)=’A 2’) or
(copy (s,1,3)=’5 5’) or (copy (s,1,3)=’4 4’) or
(copy (s,1,3)=’3 3’) or (copy (s,1,3)=’1 2’) or
(copy (s,1,3)=’k k’)then writeln (’yes’) else writeln (’no’);
end.
绝对的简练^_^
/*
http://www.rqnoj.cn/Problem_Show.asp?PID=74
Show Problem
题目:24点 问题编号:74
My Flag:Unaccepted
题目类型 搜索
描述
superwyh是一个非常疯狂的24点爱好者,空闲时总是自己拿出扑克来算24点,24点的规则很简单,就是给你4张扑克(从
1至13,用A代替1,J代替11,Q代替12,K代替13)通过加减乘除来求得24,各位oier帮了superwyh好多忙,为了报答大家
superwyh就和大家做个24点的游戏,superwyh给大家4张牌大家告诉superwyh能不能凑成24就行。
[renqing PS:这道题很easy,是送分的题]
输入格式
4张牌的牌面(1<=n<=13)。
输出格式
如果能凑成输出"yes"反之输出"no"。
样例输入
A 2 3 4
样例输出
yes
*/
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
string card="!A234567890JQK";
double pos[4];bool used[4];
bool dfs_try(int depth,double amount){
if (depth==4){
if (amount>23.999999&&amount<24.000001) return true;
else return false;
}
else{
for (int i=0;i<4;i++)
if (!used[i]){
used[i]=true;
if (dfs_try(depth+1,amount+pos[i])) return true;
if (dfs_try(depth+1,amount-pos[i])) return true;
if (dfs_try(depth+1,pos[i]-amount)) return true;
if (amount!=0&&dfs_try(depth+1,amount*pos[i])) return true;
if (amount!=0&&/*amount%pos[i]==0&&*/dfs_try(depth+1,amount/pos[i])) return true;
if (amount!=0&&/*pos[i]%amount==0&&*/dfs_try(depth+1,pos[i]/amount)) return true;
used[i]=false;
}
return false;
}
}
int main (void){
string c;
for (int i=0;i<4;i++){
cin>>c;if (c=="10")c="0";
if (c=="1") c="A";
pos[i]=(double)card.find(c);
used[i]=false;
}
if (dfs_try(0,0)==true)cout<<"yes";
else cout<<"no";
//while(1);
return 0;
}