24点游戏
来源:互联网 发布:goeasy实现java推送 编辑:程序博客网 时间:2024/06/13 08:28
样例输入
333331111125131
样例输出
24421
uses math;var a,b,c,s1,s2,s3,s4,y1,y2,y3,ans,h,o,e:longint; v:array[1..4]of longint;begin readln(a); for b:=1 to a do begin h:=0; ans:=0; readln(v[1]); readln(v[2]); readln(v[3]); readln(v[4]); for s1:=1 to 4 do begin for y1:=1 to 4 do begin for s2:=1 to 4 do begin if s1=s2 then continue; for y2:=1 to 4 do begin for s3:=1 to 4 do begin if (s1=s3)or(s2=s3) then continue; for y3:=1 to 4 do begin for s4:=1 to 4 do begin if (s1=s4)or(s2=s4)or(s3=s4) then continue; ans:=0; if y1=1 then ans:=v[s1]+v[s2]; if y1=2 then ans:=v[s1]-v[s2]; if y1=3 then ans:=v[s1]*v[s2]; if y1=4 then if (v[s2]<>0)and(v[s1] mod v[s2]=0) then ans:=v[s1] div v[s2] else continue; if y2=1 then ans:=ans+v[s3]; if y2=2 then ans:=ans-v[s3]; if y2=3 then ans:=ans*v[s3]; if y2=4 then if (v[s3]<>0)and(ans mod v[s3]=0) then ans:=ans div v[s3] else continue; if y3=1 then ans:=ans+v[s4]; if y3=2 then ans:=ans-v[s4]; if y3=3 then ans:=ans*v[s4]; if y3=4 then if (v[s4]<>0)and(ans mod v[s4]=0) then ans:=ans div v[s4] else continue; if ans<=24 then h:=max(ans,h); end; end; end; end; end; end; end; for s1:=1 to 4 do begin for y1:=1 to 4 do begin for s2:=1 to 4 do begin if s1=s2 then continue; for y2:=1 to 4 do begin for s3:=1 to 4 do begin if (s1=s3)or(s2=s3) then continue; for y3:=1 to 4 do begin for s4:=1 to 4 do begin if (s1=s4)or(s2=s4)or(s3=s4) then continue; ans:=0; if y1=1 then o:=v[s1]+v[s2]; if y1=2 then o:=v[s1]-v[s2]; if y1=3 then o:=v[s1]*v[s2]; if y1=4 then if (v[s2]<>0)and(v[s1] mod v[s2]=0) then o:=v[s1] div v[s2] else continue; if y2=1 then e:=v[s3]+v[s4]; if y2=2 then e:=v[s3]-v[s4]; if y2=3 then e:=v[s3]*v[s4]; if y2=4 then if (v[s4]<>0)and(v[s3] mod v[s4]=0) then e:=v[s3] div v[s4] else continue; if y3=1 then ans:=o+e; if y3=2 then ans:=o-e; if y3=3 then ans:=o*e; if y3=4 then if (e<>0)and(o mod e=0) then ans:=o div e else continue; if ans<=24 then h:=max(ans,h); end; end; end; end; end; end; end; writeln(h); end;end.
1 0
- 24点游戏代码
- 24点游戏
- 24点扑克牌游戏
- 24点游戏
- 24点游戏
- 《24点游戏》
- 24点游戏
- 24点游戏
- 24点游戏
- 24点游戏
- 24点游戏
- 24点游戏
- 24点游戏
- 24点游戏源码
- 24点游戏
- 24点游戏-hero
- 24点游戏
- 24点游戏算法
- 跳房子
- GCC编译选项--"-fno-strict-aliasing"
- Linux菜鸟学习之网络浅入
- 杭电ACM2005题(第几天?)------Java语言
- java 集合框架简介
- 24点游戏
- C#中internal关键字的作用
- makefile编写小结:多目录,单Makefile
- maven pom.xml详解
- HDU 2063 过山车 【匈牙利算法,二分图最大匹配】
- 直播那些事儿
- 自定义进度条
- My SQL 日期与时间函数
- Android - Custom View