• [ZJOI2012]数列


    超级水的题还wa了一次

    首先很容易发现其实就只有两个值并存

    然后 要注意把数组初始化啊。。。可能后面有多余的元素(对拍的时候由于从小到大就没跑出错)

    #include <bits/stdc++.h>
    using namespace std;
    int a[170],b[170],a1[170],a2[170],x1[170],x2[170];
    bool t;
    char s[170];
    void cf(int *a)
    {
        int x=0;
        for (int i=150;i>=1;i--)
        {
            b[i]=(x*10+a[i])/2;
            x=(x*10+a[i])%2;
        }
        memcpy(a,b,sizeof(b));
    }
    void calc1(int *a,int *b)
    {
        int x=1;
        for (int i=1;i<=150;i++)
        {
          b[i]=(a[i]+x)%10;
          x=(a[i]+x)/10;
        }
    }
    void calc2(int *a,int *b)
    {
        int x=1;
        for (int i=1;i<=150;i++)
        {
            if (x==1)
            {
                if (a[i]==0) b[i]==9;
                else b[i]=a[i]-1,x=0;
            } else b[i]=a[i];
        }
    }
    int pd(int *a)
    {
        int u=0;
        for (int i=150;i>=2;i--)
          if (a[i]>0) u=9;
        if (!u)
        {
          if (a[1]==0) return(0);
          else if (a[1]==1) return(1);
        }
        return(2);
    }
    void cc(int *a1,int *a2)
    {
        int x=0;
        for (int i=1;i<=150;i++)
        {
          b[i]=(a1[i]+a2[i]+x)%10;
          x=(a1[i]+a2[i]+x)/10;
        }
        memcpy(a1,b,sizeof(b));
    }
    void dfs()
    {
        while (true)
        {
        int tmp=pd(a1);
        if (tmp==0)
        {
            memcpy(x1,x2,sizeof(x2));
            return ;
        } else if (tmp==1)
        {
            cc(x1,x2);
            return ;
        }
        if (!pd(x2))
        {
            if (a1[1]%2==0) cf(a1); else
            {
               cf(a1);
               calc1(a1,a2); 
               memcpy(x2,x1,sizeof(x1));
            }
        } else
        {
            if (a1[1]%2==0)
            { 
                cf(a1);
                calc1(a1,a2);
                cc(x1,x2);
            } else
            {
                cf(a2);
                calc2(a2,a1); 
                cc(x2,x1);
            }
        }
        }
    }
    int main()
    {
        int T;
        cin>>T;
        for (int i=1;i<=T;i++)
        {
            cin>>s;
            memset(a,0,sizeof(a));
            for (int i=0;i<strlen(s);i++)
              a[i+1]=s[strlen(s)-i-1]-'0';
            memset(x1,0,sizeof(x1));
            memset(x2,0,sizeof(x2));
            x1[1]=1; 
            memcpy(a1,a,sizeof(a));
            dfs();
            int j;
            for (j=150;j;j--) if (x1[j]) break;
            for (int k=j;k;k--) cout<<x1[k];
            if (j==0) cout<<0;
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    angularJS 修改操作select回显选中的数据
    zkteco iface702 中控考勤机java开发步骤二---获取考勤机 的考勤数据
    zkteco iface702 中控考勤机java开发步骤一---连接考勤机
    JQuery的分页插件pagination.js
    Ajax跨域后台处理
    发送邮箱工具类--阿里企业邮箱群发
    kindeditor-4.1.10 ---文件上传
    导出excel表格
    算法
    Arrays类——Arrays.asList()方法使用
  • 原文地址:https://www.cnblogs.com/yinwuxiao/p/8556106.html
Copyright © 2020-2023  润新知