• srm 541


    资瓷点这里阅读该文章O_o

    250


    Solution

    水题,最暴力的方法枚举就可以

    Code

    #include <bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    typedef long long LL;
    typedef pair<int, int> pii;
    map<char, int> s;
    int dx[] = {0, 1, -1, 0};
    int dy[] = {1, 0, 0, -1};
    const int N = 55;
    int f[N];
    bool vis[N];
    struct AntsMeet {
        int countAnts(vector <int> x, vector <int> y, string direction) {
            int n = x.size();
            s['N'] = 0, s['E'] = 1, s['W'] = 2, s['S'] = 3;
            for (int i = 0; i < n; ++i) x[i] <<= 1, y[i] <<= 1, f[i] = s[direction[i]], vis[i] = 1;
            for (int i = 1; i <= 4001; ++i) {
                for (int j = 0; j < n; ++j)
                    if (vis[j]) {
                        for (int k = j + 1; k < n; ++k)
                            if (vis[k]) {
                                if (x[j] == x[k] && y[j] == y[k])   vis[j] = vis[k] = 0;
                            }
                    }
                for (int j = 0; j < n; ++j)
                    if (vis[j]) {
                        x[j] += dx[f[j]];
                        y[j] += dy[f[j]];
                    }
            }
            int ans = 0;
            for (int i = 0; i < n; ++i) 
                if (vis[i]) ++ans;
            return ans;
        }
    };

    550


    Description

    给出串A,B,C,S,F和整数k

    以及函数f(x)=A+x+B+x+C

    fk(x)中以F为子串,出现了多少次。答案mod 109+7

    串的长度50, k107

    Solution

    注意到串长度50,以及k107,并且出现F的情况分为在A。B。C三个串中分别出现,以及在交界处出现。因为串的长度比較小,所以我们暴力50次以后,交界处包括F的次数就不再变化了(想一想,为什么)。于是后面的情况我们每次ans=ans×2+t就可以。。t是交界处的答案,ansA,B,C中的答案。

    Code

    #include <bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    typedef long long LL;
    typedef pair<int, int> pii;
    const int M = 1e9 + 7;
    struct AkariDaisukiDiv1 {
        int gao(const string &s, const string &t, int l = 0, int r = 100000000) {
            int tmp = 0;
            for (int i = l; i < s.size() - t.size() + 1 && i < r; ++i)
                if (s.substr(i, t.size()) == t) ++tmp;
            return tmp;
        }
        int countF(string A, string B, string C, string S, string F, int k) {
            int cnt = 0;
            for (; cnt < k && S.size() < F.size(); ++cnt)   S = A + S + B + S + C;
            if (S.size() < F.size())    return 0;
            int ans = gao(S, F), t = 0; 
            string p = S.substr(0, F.size()), q = S.substr(S.size() - F.size(), F.size());
            for (int i = 0; cnt < k && i < 50; ++cnt, ++i) {
                t = gao(A + p, F, 0, A.size()) + gao(q + B + p, F, 1, F.size() + B.size()) + gao(q + C, F, 1);
                ans = (ans + ans + t) % M;
                p = (A + p).substr(0, F.size()), q = (q + C).substr((q + C).size() - F.size(), F.size());
            }
            for (; cnt < k; ++cnt)  ans = (ans + ans + t) % M;
            return ans;
        }
    };
  • 相关阅读:
    Re:从零开始的领域驱动设计
    领域驱动设计和Spring
    深入JVM分析spring-boot应用hibernate-validator
    深入Spring Boot:那些注入不了的Spring占位符(${}表达式)
    Android 使用OKhttp获取response时遇到的坑
    Android EditText组件drawableLeft属性设置的图片和hint设置的文字之间的距离
    Android 自定义spinner下拉框实现的实现
    Android You need to use a Theme.AppCompat theme (or descendant) with this activity.
    Android中取消GridView & ListView默认的点击背景色
    Android 显示 PDF 文件
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5286874.html
Copyright © 2020-2023  润新知