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
  • 相关阅读:
    Misc1
    PXE
    VCL
    pacman usage
    .vimrc的配置
    Windows Server 2012 R2
    Windows 入门杂乱无章版
    VS Code Plugins And Configuration
    「Poetize5」GF弹钢琴
    「Poetize4」上帝造题的七分钟2
  • 原文地址:https://www.cnblogs.com/laiba2004/p/3982603.html
Copyright © 2011-2022 走看看