zoukankan      html  css  js  c++  java
  • HUST 1599

    1599 - Multiple

    时间限制:2秒 内存限制:64兆
    461 次提交 111 次通过
    题目描述
    Rocket323 loves math very much. One day, Rocket323 got a number string. He could choose some consecutive digits from the string to form a number. Rocket323 loves 64 very much, so he wanted to know how many ways can he choose from the string so the number he got multiples of 64 ?

    A number cannot have leading zeros. For example, 0, 64, 6464, 128 are numbers which multiple of 64 , but 12, 064, 00, 1234 are not.
    输入
    Multiple cases, in each test cases there is only one line consist a number string.
    Length of the string is less than 3 * 10^5 .

    Huge Input , scanf is recommended.
    输出
    Print the number of ways Rocket323 can choose some consecutive digits to form a number which multiples of 64.
    样例输入
    64064
    样例输出
    5
    提示
    There are five substrings which multiples of 64.
    [64]064
    640[64]
    64[0]64
    [64064]
    [640]64
    来源
    Problem Setter : Yang Xiao

    思路:
    根据同余定理,每次枚举到一个数,都把前面的存在的余数乘以10加上这个数再对64取余,就产生新的余数,最后统计余数是0的个数有多少

    #include <iostream>
    #include <string.h>
    #include <math.h>
    #include <algorithm>
    #include <stdio.h>
    #include <stdlib.h>
    
    using namespace std;
    char a[300005];
    long long int dp[2][65];
    long long int tag[65];
    long long int ans;
    long long int res;
    int now;
    int main()
    {
        while(scanf("%s",a)!=EOF)
        {
            ans=0;res=0;
            int len=strlen(a);
            memset(dp,0,sizeof(dp));
            now=0;
            for(int i=0;i<len;i++)
            {
                for(int j=63;j>=0;j--)
                    dp[now^1][j]=0;
                for(int j=63;j>=0;j--)
                {
                    int num=(j*10+a[i]-'0'+64)%64;
                    dp[now^1][num]+=dp[now][j];
    
                }
                if(a[i]!='0')
                    dp[now^1][a[i]-'0']++;
                else
                    ans++;
                res+=dp[now^1][0];
                now^=1;
    
            }
            printf("%lld
    ",res+ans);
        }
        return 0;
    }
  • 相关阅读:
    emWin 界面切换注意事项
    emWin 工程之汉字显示
    emWin 使用 GUIBuilder 放置标题 TEXT 注意
    【转】系统调用和驱动程序中相应函数的参数对应关系
    主机 & 虚拟机 & 开发板 相互通信
    电脑通过网口连接开发板
    【转】ARM交叉编译工具链
    【转】vi 写完文件保存时才发现是 readonly
    【转】ubuntu 12.04下如何开启 NFS 服务 & 设置
    安装完打开 eclipse 提示 JVM 版本较低
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228787.html
Copyright © 2011-2022 走看看