锁定老帖子 主题:趣味编程:24点算法实现
精华帖 (0) :: 良好帖 (2) :: 新手帖 (2) :: 隐藏帖 (1)
|
|
---|---|
作者 | 正文 |
发表时间:2009-01-13
不错,我以前也实现过,也是排列穷举。有机会在优化优化,
|
|
返回顶楼 | |
发表时间:2009-01-13
kjj 写道 什么意思,紧贴楼主的问题,不能超过10,否则,人脑就无法计算了,四重循环正确结论不一定是这个,因为中间还有很多无解的!
超过10的解法很难吗?我初中的妹妹和我玩24点的时候都能做到13,还连带指数开根号的 1,1,1,8: (1+1+1)*8 1,1,1,11: (1+1)*(1+11) 1,1,1,12: 12/(1/(1+1)) (1+1/1)*12 (1+1)/(1/12) 1*(1+1)*12 (1+1)*1*12 (1+1*1)*12 1,1,1,13: (1+1)*(13-1) 1,1,2,6: (1+1)*2*6 (1+1+2)*6 (2+1+1)*6 2*(1+1)*6 1,1,2,7: (1+2)*(1+7) 1,1,2,8: (1*1+2)*8 (1/1+2)*8 (1+2)/(1/8) (1+1*2)*8 (1+2)*1*8 8/(1/(1+2)) 1*(1+2)*8 1,1,2,9: (1+2)*(9-1) 1,1,2,10: 2*(1+1+10) (1+1)*(2+10) 1,1,2,11: 1*2*(1+11) 2*(1+1*11) (1+11)/(1/2) 2/(1/(1+11)) 2*1*(1+11) 2+(1+1)*11 1+1+2*11 2*(1/1+11) 2*(1*1+11) 1,1,2,12: 12/(1/(1*2)) 2*1/1*12 1/(1/(2*12)) 12/(1-(1/2)) 12/(1/2*1) 2*(1-1+12) 1*2*1*12 1/(1/2)*12 (2-(1-1))*12 1+2*12-1 1/(1/2/12) 1/1*2*12 1-1+2*12 2*1/(1/12) 12/(1*1/2) 12/(1/1/2) 2/(1/12/1) 2*(1+12-1) 2*1*1*12 (1-1+2)*12 1*1*2*12 2/(1/12*1) 12/(1/2/1) 2/(1*1/12) 2/(1/(1*12)) 2*(12-(1-1)) 2/(1/1/12) 1*2/(1/12) 2*12-(1-1) (1+2-1)*12 1/(1/12/2) 1*12/(1/2) 1,1,2,13: 2*13-1-1 2*13-(1+1) (1+1)*13-2 2*(13-(1*1)) 2*1*(13-1) 2*(13-(1/1)) (13-1)/(1/2) 2/(1/(13-1)) 2*(1*13-1) 1*2*(13-1) 1,1,3,4: (1+1)*3*4 3*(1+1)*4 4*(1+1)*3 1,1,3,5: (1+3)*(1+5) 1,1,3,6: 1*(1+3)*6 (1+3)/(1/6) 6/(1/(1+3)) 3*(1+1+6) (1+3)*1*6 (1/1+3)*6 (1+1*3)*6 (1*1+3)*6 1,1,3,7: 1*3*(1+7) 3*(1+1*7) 3*(1*1+7) 3*(1/1+7) 3*1*(1+7) 3/(1/(1+7)) (1+3)*(7-1) (1+7)/(1/3) 1,1,3,8: 1*1*3*8 3*1/(1/8) 3*(1-1+8) (1-1+3)*8 8/(1/(1*3)) 1/(1/8/3) 8/(1/3/1) 1+3*8-1 1/1*3*8 3/(1/1/8) (3-(1-1))*8 3*(1+8-1) 1/(1/(3*8)) 1*3/(1/8) 1/(1/3/8) 3/(1*1/8) 1*3*1*8 3/(1/8*1) 1*8/(1/3) 1/(1/3)*8 3/(1/8/1) 3*1*1*8 (1+3-1)*8 8/(1/1/3) 3*8-(1-1) 8/(1/3*1) 3*1/1*8 3/(1/(1*8)) 1-1+3*8 8/(1*1/3) 3*(8-(1-1)) 1,1,3,9: 3/(1/(9-1)) 3*(9-(1/1)) (9-1)/(1/3) 1*3*(9-1) (1+1)*(3+9) 3*1*(9-1) 3*(1*9-1) 3*(9-(1*1)) 1,1,3,10: 3*(10-1-1) 3*(10-(1+1)) 1,1,3,11: (3-1)*(1+11) 。。。。。。。 11,12,12,12: 11+12/12+12 12+12/12+11 12+(12-11)*12 12/12+11+12 (12-11)*(12+12) 11,12,12,13: 11+12*13/12 11+13-12+12 12+13-12+11 11*12/12+13 12/12*11+13 11+12+13-12 13+11+12-12 12-(12-11)+13 11+12/12*13 12/12*(11+13) 12/(12/(11+13)) 12-12+11+13 11+12-12+13 11-(12-12)+13 12+13-(12-11) 12/(12/11)+13 13-12+11+12 12+11+13-12 11+13-(12-12) 12*(11+13)/12 11/12*12+13 12*13-(11*12) 11+12/(12/13) 11+13/12*12 (11+13)/12*12 11,12,13,13: (13-12)*11+13 11+(13-12)*13 13/13+11+12 11+13/13+12 12+13/13+11 (13-12)*(11+13) 11,13,13,13: 11/13*13+13 11-(13-13)+13 (11+13)/13*13 13/(13/(11+13)) 11+13+13-13 13+13-(13-11) 11+13-(13-13) 11+13*13/13 13+11+13-13 11+13-13+13 13-13+11+13 13-(13-11)+13 13*(11+13)/13 11*13/13+13 13/13*(11+13) 13/(13/11)+13 13/13*11+13 11+13/13*13 12,12,12,12: 12-12+12+12 12+12-(12-12) 12+12+12-12 12+12-12+12 12+12*12/12 12+12/12*12 12/12*(12+12) 12/(12/(12+12)) 12*(12+12)/12 (12+12)/12*12 12,12,12,13: (13-12)*(12+12) 12+(13-12)*12 12-(12/12)+13 12+13-(12/12) 12,12,13,13: 13/(13/(12+12)) 13*(12+12)/13 12+12-(13-13) (12+12)/13*13 12+12/13*13 12+13-(13-12) 13/13*(12+12) 13-13+12+12 12+13/(13/12) 12+12+13-13 12-(13-12)+13 12+13-13+12 12+13/13*12 12+12-13+13 12+12*13/13 13+12+12-13 12,13,13,13: (13+13)/13*12 12-(13/13)+13 12/13*(13+13) 12*(13+13)/13 12/(13/(13+13)) 12+13-(13/13) (13+13)/(13/12) finally: total=1820, solved=1361, noanswer=459 计算用时:42.703秒 刚做了一下统计,10以上的解答率不必1-9低多少 |
|
返回顶楼 | |
发表时间:2009-01-13
再BT了一下:只计算结果中用到了14or15的:
1,1,2,14: 2*(14-1-1) 2*(14-(1+1)) (1+1)*(14-2) 1,1,3,15: (1+1)*(15-3) 1,1,4,14: (1+1)*14-4 1,1,5,14: (1+1)*5+14 1,1,6,15: (1+1)*15-6 1,1,7,15: 7+1+1+15 1+7+1+15 1+1+7+15 1,1,8,14: 8+1+1+14 1+1+8+14 1+8+1+14 1,1,8,15: 8+1+1*15 1*(8+1+15) 1+1*8+15 1+1*(8+15) 8+1*1+15 1*(1+8)+15 8+1*(1+15) 1*1+8+15 1*8+1+15 1*(1+8+15) 1/1+8+15 8+1/1+15 1+8+1*15 1,1,9,14: 1*(1+9+14) 1+1*9+14 1*1+9+14 9+1*1+14 1*(1+9)+14 9+1*(1+14) 1+1*(9+14) 1*(9+1+14) 9+1+1*14 1/1+9+14 1*9+1+14 1+9+1*14 9+1/1+14 1,1,9,15: 1+9-1+15 9+1/(1/15) 1/1*9+15 1-1+9+15 9+1-1+15 1*(9+1*15) 1*1*9+15 1+9+15-1 1*9+1*15 1/(1/9)+15 9+1+15-1 1*(1*9+15) 9-(1-1)+15 9-1+1+15 9+1*1*15 1*1*(9+15) 9+15-(1-1) 1/(1/(9+15)) 1/1*(9+15) 9+1/1*15 1,1,10,14: 1-1+10+14 1+10+14-1 1*1*(10+14) 1*1*10+14 10-1+1+14 1/1*10+14 10+1/(1/14) 10+14-(1-1) 10+1/1*14 10+1*1*14 1*(1*10+14) 10+1-1+14 1/(1/10)+14 1/1*(10+14) 10-(1-1)+14 1*(10+1*14) 10+1+14-1 1*10+1*14 1/(1/(10+14)) 1+10-1+14 1,1,10,15: 10+15-(1/1) 1*10-1+15 1*(10-1)+15 1*10+15-1 10+1*(15-1) 1*(10+15)-1 10-1+1*15 10-(1/1)+15 10-(1*1)+15 1*(10-1+15) 10+15-(1*1) 1*(10+15-1) 10+1*15-1 。。。。。 12,12,13,15: 12*15-(12*13) 12,12,14,14: 14/(14/(12+12)) 12-(14-12)+14 12+12/14*14 14+12+12-14 12+12-14+14 12+12+14-14 12+12-(14-14) 14*(12+12)/14 14/14*(12+12) 14-14+12+12 12+14/(14/12) 12+14/14*12 12+14-14+12 12+14-(14-12) 12+12*14/14 (12+12)/14*14 12,12,14,15: (15-14)*(12+12) 12+(15-14)*12 12,12,15,15: 12+12-(15-15) 12+12/15*15 (12+12)/15*15 12-(15-12)+15 12+15/15*12 15*(12+12)/15 12+12-15+15 15-15+12+12 12+15/(15/12) 12+15-(15-12) 12+12+15-15 15+12+12-15 15/(15/(12+12)) 12+12*15/15 12+15-15+12 15/15*(12+12) 12,13,13,14: 13+12+13-14 13+13-(14-12) 13-(14-12)+13 12-(14-13)+13 12+13-(14-13) 12+13-14+13 12+13+13-14 12,13,14,14: 12+13-(14/14) 12-(14/14)+13 12,13,14,15: 12*(13+15)/14 (13+15)/(14/12) 14-(15-12)+13 13+14-(15-12) 13-(15-12)+14 12-(15-13)+14 12+13+14-15 12-(15-14)+13 12/(14/(13+15)) 14+12+13-15 (13+15)/14*12 12+13-15+14 12+14-(15-13) 12+13-(15-14) 12+14-15+13 13+12+14-15 12/14*(13+15) 12,13,15,15: 12-(15/15)+13 (15-12)*13-15 12+13-(15/15) 12,14,14,14: (14+14)/(14/12) 12*(14+14)/14 (14+14)/14*12 12/14*(14+14) 12/(14/(14+14)) 12,15,15,15: (15+15)/15*12 12/(15/(15+15)) 12/15*(15+15) (15+15)/(15/12) 12*(15+15)/15 13,13,13,15: 13+13+13-15 13-(15-13)+13 13+13-(15-13) 13+13-15+13 finally: total=3060, solved=832, noanswer=2228 计算用时:87.375秒 也不少哦 |
|
返回顶楼 | |
发表时间:2009-01-13
楼上的帖子厉害!
|
|
返回顶楼 | |
发表时间:2009-01-13
最后BT了一把:用到特殊符号 && 含14or15
1,5,12,14: (5^(14-12))-1 2,7,8,14: 7+(2log8)+14 (2log8)+7+14 2,9,13,15: (2√9)*13-15 3,3,12,14: 3*((14-12)^3) 3,4,8,14: (3√8)*14-4 3,5,9,14: (3log9)*5+14 3,7,7,14: ((7^3)-7)/14 3,7,8,15: 7+(3√8)+15 (3√8)+7+15 3,8,9,14: (3log9)+8+14 ((14-8)^3)/9 8+(3log9)+14 3,8,12,15: (3√(12+15))*8 (3log(12+15))*8 3,9,9,15: ((15-9)^3)/9 6,9,11,14: (6^(14-11))/9 8,9,12,14: ((14-12)√9)*8 8,9,13,15: ((15-13)√9)*8 |
|
返回顶楼 | |
发表时间:2009-01-13
graying 写道 kjj 写道 什么意思,紧贴楼主的问题,不能超过10,否则,人脑就无法计算了,四重循环正确结论不一定是这个,因为中间还有很多无解的!
超过10的解法很难吗?我初中的妹妹和我玩24点的时候都能做到13,还连带指数开根号的 1,1,1,8: (1+1+1)*8 1,1,1,11: (1+1)*(1+11) 1,1,1,12: 12/(1/(1+1)) (1+1/1)*12 (1+1)/(1/12) 1*(1+1)*12 (1+1)*1*12 (1+1*1)*12 1,1,1,13: (1+1)*(13-1) 1,1,2,6: (1+1)*2*6 (1+1+2)*6 (2+1+1)*6 2*(1+1)*6 1,1,2,7: (1+2)*(1+7) 1,1,2,8: (1*1+2)*8 (1/1+2)*8 (1+2)/(1/8) (1+1*2)*8 (1+2)*1*8 8/(1/(1+2)) 1*(1+2)*8 1,1,2,9: (1+2)*(9-1) 1,1,2,10: 2*(1+1+10) (1+1)*(2+10) 1,1,2,11: 1*2*(1+11) 2*(1+1*11) (1+11)/(1/2) 2/(1/(1+11)) 2*1*(1+11) 2+(1+1)*11 1+1+2*11 2*(1/1+11) 2*(1*1+11) 1,1,2,12: 12/(1/(1*2)) 2*1/1*12 1/(1/(2*12)) 12/(1-(1/2)) 12/(1/2*1) 2*(1-1+12) 1*2*1*12 1/(1/2)*12 (2-(1-1))*12 1+2*12-1 1/(1/2/12) 1/1*2*12 1-1+2*12 2*1/(1/12) 12/(1*1/2) 12/(1/1/2) 2/(1/12/1) 2*(1+12-1) 2*1*1*12 (1-1+2)*12 1*1*2*12 2/(1/12*1) 12/(1/2/1) 2/(1*1/12) 2/(1/(1*12)) 2*(12-(1-1)) 2/(1/1/12) 1*2/(1/12) 2*12-(1-1) (1+2-1)*12 1/(1/12/2) 1*12/(1/2) 1,1,2,13: 2*13-1-1 2*13-(1+1) (1+1)*13-2 2*(13-(1*1)) 2*1*(13-1) 2*(13-(1/1)) (13-1)/(1/2) 2/(1/(13-1)) 2*(1*13-1) 1*2*(13-1) 1,1,3,4: (1+1)*3*4 3*(1+1)*4 4*(1+1)*3 1,1,3,5: (1+3)*(1+5) 1,1,3,6: 1*(1+3)*6 (1+3)/(1/6) 6/(1/(1+3)) 3*(1+1+6) (1+3)*1*6 (1/1+3)*6 (1+1*3)*6 (1*1+3)*6 1,1,3,7: 1*3*(1+7) 3*(1+1*7) 3*(1*1+7) 3*(1/1+7) 3*1*(1+7) 3/(1/(1+7)) (1+3)*(7-1) (1+7)/(1/3) 1,1,3,8: 1*1*3*8 3*1/(1/8) 3*(1-1+8) (1-1+3)*8 8/(1/(1*3)) 1/(1/8/3) 8/(1/3/1) 1+3*8-1 1/1*3*8 3/(1/1/8) (3-(1-1))*8 3*(1+8-1) 1/(1/(3*8)) 1*3/(1/8) 1/(1/3/8) 3/(1*1/8) 1*3*1*8 3/(1/8*1) 1*8/(1/3) 1/(1/3)*8 3/(1/8/1) 3*1*1*8 (1+3-1)*8 8/(1/1/3) 3*8-(1-1) 8/(1/3*1) 3*1/1*8 3/(1/(1*8)) 1-1+3*8 8/(1*1/3) 3*(8-(1-1)) 1,1,3,9: 3/(1/(9-1)) 3*(9-(1/1)) (9-1)/(1/3) 1*3*(9-1) (1+1)*(3+9) 3*1*(9-1) 3*(1*9-1) 3*(9-(1*1)) 1,1,3,10: 3*(10-1-1) 3*(10-(1+1)) 1,1,3,11: (3-1)*(1+11) 。。。。。。。 11,12,12,12: 11+12/12+12 12+12/12+11 12+(12-11)*12 12/12+11+12 (12-11)*(12+12) 11,12,12,13: 11+12*13/12 11+13-12+12 12+13-12+11 11*12/12+13 12/12*11+13 11+12+13-12 13+11+12-12 12-(12-11)+13 11+12/12*13 12/12*(11+13) 12/(12/(11+13)) 12-12+11+13 11+12-12+13 11-(12-12)+13 12+13-(12-11) 12/(12/11)+13 13-12+11+12 12+11+13-12 11+13-(12-12) 12*(11+13)/12 11/12*12+13 12*13-(11*12) 11+12/(12/13) 11+13/12*12 (11+13)/12*12 11,12,13,13: (13-12)*11+13 11+(13-12)*13 13/13+11+12 11+13/13+12 12+13/13+11 (13-12)*(11+13) 11,13,13,13: 11/13*13+13 11-(13-13)+13 (11+13)/13*13 13/(13/(11+13)) 11+13+13-13 13+13-(13-11) 11+13-(13-13) 11+13*13/13 13+11+13-13 11+13-13+13 13-13+11+13 13-(13-11)+13 13*(11+13)/13 11*13/13+13 13/13*(11+13) 13/(13/11)+13 13/13*11+13 11+13/13*13 12,12,12,12: 12-12+12+12 12+12-(12-12) 12+12+12-12 12+12-12+12 12+12*12/12 12+12/12*12 12/12*(12+12) 12/(12/(12+12)) 12*(12+12)/12 (12+12)/12*12 12,12,12,13: (13-12)*(12+12) 12+(13-12)*12 12-(12/12)+13 12+13-(12/12) 12,12,13,13: 13/(13/(12+12)) 13*(12+12)/13 12+12-(13-13) (12+12)/13*13 12+12/13*13 12+13-(13-12) 13/13*(12+12) 13-13+12+12 12+13/(13/12) 12+12+13-13 12-(13-12)+13 12+13-13+12 12+13/13*12 12+12-13+13 12+12*13/13 13+12+12-13 12,13,13,13: (13+13)/13*12 12-(13/13)+13 12/13*(13+13) 12*(13+13)/13 12/(13/(13+13)) 12+13-(13/13) (13+13)/(13/12) finally: total=1820, solved=1361, noanswer=459 计算用时:42.703秒 刚做了一下统计,10以上的解答率不必1-9低多少 回答别人问题请抓住主题! |
|
返回顶楼 | |
发表时间:2009-01-13
初中的妹妹心算会求指数,开根号是吧!
|
|
返回顶楼 | |
发表时间:2009-01-13
楼上请莫激动,没有冒犯的意思,呵呵。有言语不佳,罪过罪过
开根号是我教我妹的,指数她好像原本就会,这是事实 |
|
返回顶楼 | |
发表时间:2009-01-13
回到lZ的主题,24 Math Game的算法核心其实就是Cx2 求解,然后去除一些异类,优化一下速度,并不要考虑各种先后次序太复杂化了
|
|
返回顶楼 | |
发表时间:2009-01-13
没什么激动,只是求解而已
|
|
返回顶楼 | |