码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2266 How Many Equations Can You Find(模拟,深搜)

时间:2014-09-19 23:43:16      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   div   

题目

 

这是传说中的深搜吗。。。。不确定,,,,貌似更加像是模拟,,,,

 

bubuko.com,布布扣
//我要做深搜题目拉
//实际上还是模拟

#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int ans;
char a[20];
__int64 n;
int fuhao[20];
int len;
__int64 cal()
{
    int fh=0;
    __int64 num=0,tmp=0;
    tmp=a[0]-0;
    for(int i=1;i<len;i++){
        if(fuhao[i-1]==1){
            if(fh==1)num+=tmp;
            else if(fh==2)num-=tmp;
            else if(fh==0)num=tmp;
            tmp=0;
            fh=1;
        }
        else if(fuhao[i-1]==2){
            if(fh==1)num+=tmp;
            else if(fh==2)num-=tmp;
            else if(fh==0)num=tmp;
            tmp=0;
            fh=2;
        }
        tmp=tmp*10+a[i]-0;
    }
    if(fh==1)num+=tmp;
    else if(fh==2)num-=tmp;
    else num=tmp;
    return num;
}
void dfs(int st)
{
    if(st==len-1){//符号比数少一位
        if(cal()==n)ans++;
        return;
    }
    fuhao[st]=0;
    dfs(st+1);
    fuhao[st]=1;
    dfs(st+1);
    fuhao[st]=2;
    dfs(st+1);
}

int main()
{
    while(scanf("%s%I64d",a,&n)!=EOF)
    {
        memset(fuhao,0,sizeof(fuhao));
        len=strlen(a);
        ans=0;
        dfs(0);
        printf("%d\n",ans);
    }
    return 0;
}
View Code

 

HDU 2266 How Many Equations Can You Find(模拟,深搜)

标签:style   blog   http   color   io   os   ar   for   div   

原文地址:http://www.cnblogs.com/laiba2004/p/3982603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!