zoukankan      html  css  js  c++  java
  • HUST 1599 Multiple

    首先,1000000能被64整除。

    也就是说Y=X*1000000+P,当P能被64整除(P在1--6位之间),X任意的时候,Y也能被64整除。因此暴力算一下1--6位的数字中哪些能被64整除,再看看这些数组成Y形式的有几种。

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    
    char s[300000 + 10];
    long long tot[300000 + 10];
    long long ans;
    int size;
    
    int main()
    {
        while (~scanf("%s", s)){
            ans = 0; memset(tot, 0, sizeof tot); size = strlen(s);
            for (int i = 0; s[i]; i++)
            {
                if (s[i] == '0') tot[i] = tot[i - 1];
                else tot[i] = tot[i - 1] + 1;
            }
    
            for (int len = 1; len <= 6; len++)
            {
                for (int i = 0; s[i]; i++)
                {
                    if (s[i] == '0'&&len != 1) continue;
                    if (i + len - 1 >= size) continue;
                    int num = 0;
                    for (int j = i; j <= i + len - 1; j++) num = num * 10 + s[j] - '0';
    
                    if (num % 64 == 0)
                    {
                        ans++;
    
                        bool fail = 0;
                        if (i + len - 6 <= 0) fail = 1;
                        for (int j = i - 1; j >= i + len - 6; j--)
                        if (s[j] != '0') fail = 1;
    
                        if (fail == 0) ans = ans + tot[i + len - 7];
                    }
                }
            }
            printf("%lld
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    监听器
    事务
    DBUtils
    EL技术,JSTL技术与javaEE开发模式
    JSP技术
    Cookie and Session
    HttpServletRequest
    Servlet
    Http与Tomcat服务器的简单配置
    XML
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5249319.html
Copyright © 2011-2022 走看看