HDU 2266 How Many Equations Can You Find(模拟,深搜)
这是传说中的深搜吗。。。。不确定,,,,貌似更加像是模拟,,,,
//我要做深搜题目拉
//实际上还是模拟 #include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int ans;
char a[];
__int64 n;
int fuhao[];
int len;
__int64 cal()
{
int fh=;
__int64 num=,tmp=;
tmp=a[]-'';
for(int i=;i<len;i++){
if(fuhao[i-]==){
if(fh==)num+=tmp;
else if(fh==)num-=tmp;
else if(fh==)num=tmp;
tmp=;
fh=;
}
else if(fuhao[i-]==){
if(fh==)num+=tmp;
else if(fh==)num-=tmp;
else if(fh==)num=tmp;
tmp=;
fh=;
}
tmp=tmp*+a[i]-'';
}
if(fh==)num+=tmp;
else if(fh==)num-=tmp;
else num=tmp;
return num;
}
void dfs(int st)
{
if(st==len-){//符号比数少一位
if(cal()==n)ans++;
return;
}
fuhao[st]=;
dfs(st+);
fuhao[st]=;
dfs(st+);
fuhao[st]=;
dfs(st+);
} int main()
{
while(scanf("%s%I64d",a,&n)!=EOF)
{
memset(fuhao,,sizeof(fuhao));
len=strlen(a);
ans=;
dfs();
printf("%d\n",ans);
}
return ;
}
HDU 2266 How Many Equations Can You Find(模拟,深搜)的更多相关文章
- HDOJ(HDU).2266 How Many Equations Can You Find (DFS)
HDOJ(HDU).2266 How Many Equations Can You Find (DFS) [从零开始DFS(9)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零 ...
- hdu 4740【模拟+深搜】.cpp
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...
- hdu - 2266 How Many Equations Can You Find (简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2266 给一个字符串和一个数n,在字符串中间可以插入+或者 -,问有多少种等于n的情况. 要注意任意两个数之间都可 ...
- HDU 2266 How Many Equations Can You Find(DFS)
How Many Equations Can You Find Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 2266 dfs+1258
How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- hdu 5648 DZY Loves Math 组合数+深搜(子集法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5648 题意:给定n,m(1<= n,m <= 15,000),求Σgcd(i|j,i&am ...
- 深搜基础题目 杭电 HDU 1241
HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...
- (深搜)Oil Deposits -- hdu -- 1241
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 1518 Square(深搜+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...
随机推荐
- HDU 4509
很简单的排序题而已. #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- SQLiteOpenHelper/SQLiteDatabase/Cursor源代码解析
转载请注明出处:http://blog.csdn.net/y_zhiwen/article/details/51583188 Github地址.欢迎star和follow 新增android sqli ...
- Spring 计时器 @Scheduled cron 含义
Spring 计时器 @Scheduled cron 含义 学习:http://blog.csdn.net/prisonbreak_/article/details/49180307 http://b ...
- 2.6-NAT
2.6-NAT 网络地址转换协议NAT(Network Address Translation): 交换和远程都要用,先上什么就放在哪一块讲,具体来说NAT还是属于远程的. ...
- STM32F407VG (五)定时器
一.定时器节本分类和主要特点 1.STM32定时器分类: 1)看门狗定时器 2)SysTick定时器 3)RTC定时器 4)通用定时器 a)通用定时器TIM2~TIM5, 当中TIM2和TIM5是32 ...
- Python常用模块【sys】
sys.argv 参数 「argv」是「argument variable」参数变量的简写形式.一般在命令行调用的时候由系统传递给程序.这个变量其实是一个List列表,argv[0] 一般是“被 ...
- ubuntu系统启动qtceator时提示:Qt5.5.1/Tools/QtCreator/lib/qtcreator/plugins/libHelp.so: 无法加载库
在ubuntu系统下安装好qt5.5后启动qtceator时提示:Qt5.5.1/Tools/QtCreator/lib/qtcreator/plugins/libHelp.so: 无法加载库Qt5. ...
- Choose the best route HDU杭电2680【dijkstra算法 || SPFA】
http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one ...
- Grafana+Zabbix+Prometheus 监控系统
环境说明 软件 版本 操作系统 IP地址 Grafana 5.4.3-1 Centos7.5 192.168.18.231 Prometheus 2.6.1 Centos7.5 192.168.18. ...
- BZOJ 3681 线段树合并+网络流
思路: 暴力建图有n*m条边 考虑怎么优化 (那就只能加个线段树了呗) 然后我就不会写了..... 抄了一波题解 //By SiriusRen #include <bits/stdc++.h&g ...