zoukankan      html  css  js  c++  java
  • zoj 4054

    #define ll long long 
    const int N =1e5+9;
    int t;
    ll ans,tmp;
    char s[N];
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%s",s);
            int l=strlen(s);
            if(s[0]=='1') ans=1ll;
            else ans=2ll;
            tmp=ans;        
            for(int i=1;i<l;i++)
            {
                //tmp:到s[i-1](终点)的所有代价和
                //都在重复
                /*
                例如 :
                2
                0 1 2
                1 2
                3
                0 1 2 3
                1 2 3
                2 3//多的
                */
                if(s[i]=='1') tmp+=1;//由s[i-1]到s[i]的代价
                else tmp+=2;
                if(s[i]==s[i-1]) tmp+=(2*i);
                else tmp+=i;//i条路,到3的时候,i==2 ,而前面由0 1 2 3|1 2 3两条路
                /*
                 0 0 :s[i-1]到s[i]的代价为2
                 1 1 :s[i-1]到s[i]的代价为2
                 0 1 :s[i-1]到s[i]的代价为1
                 1 0 : s[i-1]到s[i]的代价为1
                */
                ans+=tmp;//累加一每个点为终点的代价和
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    GDB 用法
    C编程规范
    PHP面向对象
    cron定时任务
    Apatche配置基础
    正则表达式笔记
    PHP在windows下命令行方式
    面试题
    struts与ajax的关系
    ORACLE DUAL表详解
  • 原文地址:https://www.cnblogs.com/tingtin/p/9665846.html
Copyright © 2011-2022 走看看