zoukankan      html  css  js  c++  java
  • 2019牛客暑期多校训练营(第四场)- K number

    思维

    不难想到300的倍数就是既是3的倍数也是100的倍数。

    3的倍数的特征是各位之和为3的倍数,100的倍数后两位一定是0。

    我们可以预处理出前缀和模3的结果,然后在每一次末尾连续两个0的时候统计答案,也就是加上之前模数相同的前缀的数量

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define full(a, b) memset(a, b, sizeof a)
    #define FAST_IO ios::sync_with_stdio(false)
    using namespace std;
    typedef long long LL;
    inline int lowbit(int x){ return x & (-x); }
    inline int read(){
        int ret = 0, w = 0; char ch = 0;
        while(!isdigit(ch)){
            w |= ch == '-', ch = getchar();
        }
        while(isdigit(ch)){
            ret = (ret << 3) + (ret << 1) + (ch ^ 48);
            ch = getchar();
        }
        return w ? -ret : ret;
    }
    inline int lcm(int a, int b){ return a / __gcd(a, b) * b; }
    template <typename A, typename B, typename C>
    inline A fpow(A x, B p, C lyd){
        A ans = 1;
        for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
        return ans;
    }
    const int N = 100005;
    char s[N];
    int sum[N];
    LL cnt[3];
    
    int main(){
    
        scanf("%s", s + 1);
        int len = strlen(s + 1);
        LL ans = 0;
        for(int i = 1; i <= len; i ++){
            sum[i] = (sum[i - 1] + (s[i] - '0')) % 3;
            if(s[i] == '0') ans ++;
        }
        cnt[0] ++;
        for(int i = 1; i <= len; i ++){
            if(i + 1 <= len && s[i] == '0' && s[i + 1] == '0') ans += cnt[sum[i]];
            cnt[sum[i]] ++;
        }
        printf("%lld
    ", ans);
        return 0;
    }
    
  • 相关阅读:
    在线安装eclipse中html/jsp/xml editor插件 eclipseeditor
    webstorm 破解方式
    c# 下实现ping 命令操作
    Newtonsoft 序列化和反序列化特殊处理
    jquery 页面滚动到底部自动加载插件集合
    Bootstrap 模态对话框只加载一次 remote 数据的解决办法
    CSS文本溢出处理
    js 操作table
    Js 冒泡事件阻止
    WCF4.0 –- RESTful WCF Services
  • 原文地址:https://www.cnblogs.com/onionQAQ/p/11256271.html
Copyright © 2011-2022 走看看