hdu 1427 速算24点 dfs暴力搜索
速算24点
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
3 3 8 8
No
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define esp 0.00000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int a[];
int ans;
int getnum(string a)
{
if(a[]=='')
return ;
if(a[]>=''&&a[]<='')
return a[]-'';
if(a[]=='A')
return ;
if(a[]=='J')
return ;
if(a[]=='K')
return ;
if(a[]=='Q')
return ;
}
void dfs(int num,int gg,int step)
{
if(step==)
{
if(num==)
ans=;
return;
}
//不加括号
dfs(num+gg,a[step+],step+);
dfs(num-gg,a[step+],step+);
dfs(num*gg,a[step+],step+);
if(gg!=&&num%gg==)
dfs(num/gg,a[step+],step+);
//加括号
if(step!=)
{
dfs(num,gg+a[step+],step+);
dfs(num,gg*a[step+],step+);
dfs(num,gg-a[step+],step+);
if(a[step+]!=&&gg%a[step+]==)
dfs(num,gg/a[step+],step+);
}
}
string ch[];
int main()
{
int x,y,z,i,t;
while(cin>>ch[]>>ch[]>>ch[]>>ch[])
{
ans=;
for(i=;i<;i++)
a[i]=getnum(ch[i]);
sort(a,a+);
do
{
dfs(a[],a[],);
}
while(next_permutation(a,a+));
if(ans)
printf("Yes\n");
else
printf("No\n");
}
return ;
}
hdu 1427 速算24点 dfs暴力搜索的更多相关文章
- hdu 1427 速算24点【暴力枚举】
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- [HDU 1427]速度计算24点(DFS暴力搜索)
主题连接: pid=1427">http://acm.hdu.edu.cn/showproblem.php?pid=1427 思路:简单的DFS.dfs(sum,next,p)表 ...
- hdu 1427 速算24点
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1427 速算24点 Description 速算24点相信绝大多数人都玩过.就是随机给你四张牌,包括A( ...
- HDU 1427 速算24点【数值型DFS】
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 1427 速算24点 (深搜)
题目链接 Problem Description 速算24点相信绝大多数人都玩过.就是随机给你四张牌,包括A(1),2,3,4,5,6,7,8,9,10,J(11),Q(12),K(13).要求只用' ...
- 24点游戏&&速算24点(dfs)
24点游戏 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Sta ...
- Hdu1427 速算24点 2017-01-18 17:26 46人阅读 评论(0) 收藏
速算24点 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submiss ...
- hdu1427之速算24点
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
随机推荐
- [py]flask蓝图的使用
参考 flask挺挺轻巧的, 因此玩一玩它. 如果用它做大型点的项目, 就用到了它的蓝图组织项目. 一时半会不太清楚这玩意怎么用, 得撸一撸py基础了. 我搞了个movie小的flask栗子来用用蓝图 ...
- [LeetCode] 821. Shortest Distance to a Character_Easy tag: BFS
Given a string S and a character C, return an array of integers representing the shortest distance f ...
- 机器学习理论基础学习17---贝叶斯线性回归(Bayesian Linear Regression)
本文顺序 一.回忆线性回归 线性回归用最小二乘法,转换为极大似然估计求解参数W,但这很容易导致过拟合,由此引入了带正则化的最小二乘法(可证明等价于最大后验概率) 二.什么是贝叶斯回归? 基于上面的讨论 ...
- loadrunner获取接口返回参数(包括body,headers等)
Action() { web_set_max_html_param_len("); // 默认最大长度为256 web_reg_save_param("ResponseBody&q ...
- EXTJS 4:在renderer中如何控制一个CheckColumn的行为,如显示,只读等属性
在编写grid下的column时,大家肯定会经常用到renderer这个方法来改变文字的呈现形式,那么如果该column是一个特殊的column,比如CheckColumn时,该方法应该怎样写呢?官方 ...
- react native 淘宝镜像
终端命令 open 打开 .npmrc 插入一行代码 registry=https://registry.npm.taobao.org
- Look for the Air Jordan 32 in full family sizing
Following the release of the 'Rosso Corsa' colorway, Jordan Brand is now set to officially launch th ...
- 几乎考虑到了每个细节的php图片上传
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> < ...
- 多项式函数插值:多项式形式函数求值的Horner嵌套算法
设代数式序列 $q_1(t), q_2(t), ..., q_{n-1}(t)$ ,由它们生成的多项式形式的表达式(不一定是多项式): $$p(t)=x_1+x_2q_1(t)+...x_nq_1(t ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON SetComprise1
zw版[转发·台湾nvp系列Delphi例程]HALCON SetComprise1 procedure TForm1.Button1Click(Sender: TObject);var image0 ...