zoukankan      html  css  js  c++  java
  • 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[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
    ",ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    centos 6 安装
    DNS介绍
    Saltstack远程执行(四)
    Saltstack数据系统Grains和Pillar(三)
    array_multisort 二维数组排序
    jqgit...
    Redis 创建多个端口 链接redis端口
    百度商桥回话接口
    加ico
    redis 新开端口号
  • 原文地址:https://www.cnblogs.com/laiba2004/p/3982603.html
Copyright © 2011-2022 走看看