• arc110b


    arc110b

    大意

    给定一个长为 (N) 且仅有 (0,1) 的串,问:

    给定串在 (10^{10})(110) 首尾相接连成的串中出现了几次(位置可以有重复!)

    思路

    第一次以为不能重复...不看样例的后果

    先考虑最特殊的情况,给定串为 (1) ,此时答案是 (2*10^{10})

    然后以第一个 (110) 的三个位置为开头,必须要能够匹配,否则不存在。

    不妨假设在第一个 (110)(0) 处开始,并完成了匹配。

    那么一次匹配跨越的 (110) 的个数显然为 (num=(2+n+2)/3) 向下取整。

    然后,我们删去第一个 (110) ,因为排除最特殊的情况后,一个 (110) 不可能同时作为开头两次。

    最后答案显然为 (10^{10}-num+1)

    代码

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    using namespace std;
    
    #define ll long long
    #define ull unsigned long long
    #define cint const int&
    #define Pi acos(-1)
    
    const int mod = 998244353;
    const int inf_int = 0x7fffffff;
    const ll inf_ll = 0x7fffffffffffffff;
    const double ept = 1e-9;
    
    string a;
    int n;
    char t[3] = {'1', '1', '0'};
    ll l = 0;
    
    int main() {
        bool flag=0;
        cin >> n >> a;
        if(a == "1" ) {
            cout << (ll)(2*1e10) << endl;
            return 0;
        }
        for(int i=0; i<3; i++) {
            for(int j=0; j<n; j++) {
                if(t[(i+j)%3] != a[j]) break;
                if(j == n-1) flag=1;
            }
            if(flag) {
                ll ans = 1e10 - (n+i+2)/3 + 1;
                cout << ans << endl;
                return 0;
            }
        }
        cout << 0 << endl;
        return 0;
    }
    

    -2,40min

  • 相关阅读:
    test
    有偏估计和无偏估计
    Spark Shuffle
    Adaboost算法推导
    Spark优化 – 基础篇
    决策树 – 回归
    HBase的文件合并(minor/major compact)
    HBase的列式存储
    centos7配置固定ip
    Generate a Certificate Signing Request (CSR) in macOS Keychain Access
  • 原文地址:https://www.cnblogs.com/ullio/p/14117316.html
Copyright © 2020-2023  润新知