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 ...
随机推荐
- 为什么要用Markov chain Monte Carlo (MCMC)
马尔科夫链的蒙特卡洛采样的核心思想是构造一个Markov chain,使得从任意一个状态采样开始,按该Markov chain转移,经过一段时间的采样,逼近平稳分布stationary distrib ...
- [LeetCode] 127. Word Ladder _Medium tag: BFS
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest t ...
- python 一个.py文件如何调用另一个.py文件中的类和函数
原文地址https://blog.csdn.net/winycg/article/details/78512300 在同一个文件夹下 调用函数:
- 面经:Bloomberg Internship第一轮
上来先问了一个系统设计的问题,一个front end, 一个back end. front end有很多UI,一个UI对10个多customers,back end有许多processor,或者pro ...
- 面试问题整理之python测试
1.下列哪个语句在Python中是非法的? A.x = y = z =1 B.x = (y = z + 1) C.x, y = y, x D.x += y 答案:B 2.关于Python内存管理,下列 ...
- Centos下yum安装Nginx报错 No package nginx available.
在Centos6下使用yum安装Nginx报错 解决方案: yum install epel-release
- jquery的click无法触发事件
一个页面需要在加载后勾选table中所有行的checkbox,于是就这样写 $("table thead tr th input[type='checkbox']").click( ...
- 20145225《网络对抗》Exp6 信息搜集与漏洞扫描
基础问题回答 哪些组织负责DNS,IP的管理: 全球根服务器均由美国政府授权的ICANN统一管理,负责DNS和IP地址管理.全球一共有5个地区性注册机构:ARIN(北美地区业务),RIPE(负责欧洲地 ...
- Zigbee学习
(一)Zigbee简介和开发环境快速建立(IAR) 1.我不是很清楚控制链条,对于Zigbee不是太清楚 答案:CC2530 芯片上集成了 8051 内核(增强型) 2.性能特点:低速率远距离,这造就 ...
- poj 1274 The Prefect Stall - 二分匹配
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22736 Accepted: 10144 Description Far ...