24 Point game
时间限制:3000 ms | 内存限制:65535 KB 难度:5- 描述
-
There is a game which is called 24 Point game.
In this game , you will be given some numbers. Your task is to find an expression which have all the given numbers and the value of the expression should be 24 .The expression mustn't have any other operator except plus,minus,multiply,divide and the brackets.
e.g. If the numbers you are given is "3 3 8 8", you can give "8/(3-8/3)" as an answer. All the numbers should be used and the bracktes can be nested.
Your task in this problem is only to judge whether the given numbers can be used to find a expression whose value is the given number。
- 输入
-
The input has multicases and each case contains one line
The first line of the input is an non-negative integer C(C<=100),which indicates the number of the cases.
Each line has some integers,the first integer M(0<=M<=5) is the total number of the given numbers to consist the expression,the second integers N(0<=N<=100) is the number which the value of the expression should be.
Then,the followed M integer is the given numbers. All the given numbers is non-negative and less than 100
- 输出
- For each test-cases,output "Yes" if there is an expression which fit all the demands,otherwise output "No" instead.
- 样例输入
-
2 4 24 3 3 8 8 3 24 8 3 3
- 样例输出
-
Yes No
-
#include#include #include #include #include #include #include #include //#define MIN 1e-10 using namespace std; const double MIN=1e-10;//const double,习惯性的写成const int 导致搞了一个晚上 double a[10]; int n; double num; bool DFS(int x) { if(x==n) { if(fabs(num-a[n])
- <script type="text/java script">BAIDU_CLB_fillSlot("771048");
- 点击复制链接 与好友分享! 回本站首页 <script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)]; - 您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力??
- 上一篇: LeetCode题解: LRU Cache 缓存设计
- 下一篇: 最后一页
- 相关文章
编程之美1.16――24点游戏
- <script type="text/java script">BAIDU_CLB_fillSlot("182716");
- <script type="text/java script">BAIDU_CLB_fillSlot("517916");
- 图文推荐
<iframe src="http://www.2cto.com/uapi.php?tid=359725&catid=339&title=TllPSi00MyAyNCBQb2ludCBnYW1lLURGUw==&forward=http://www.2cto.com/kf/201412/359725.html" width="100%" height="100%" id="comment_iframe" name="comment_iframe" frameborder="0" scrolling="no">
- <script type="text/java script">BAIDU_CLB_fillSlot("771057");



