资瓷点这里阅读该文章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, k≤107

Solution

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

srm 541的更多相关文章

  1. 1Z0-053 争议题目解析541

    1Z0-053 争议题目解析541 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 541.If you use ALTER DISKGROUP ... ADD DISK and s ...

  2. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  3. SRM 513 2 1000CutTheNumbers(状态压缩)

    SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...

  4. SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)

    SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...

  5. SRM 657 DIV2

    -------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...

  6. [RabbitMQ] AMQP close-reason, initiated by Library, code=541

    RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachabl ...

  7. SRM DIV1 500pt DP

    SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...

  8. TC srm 673 300 div1

    TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能 ...

  9. SRM 584 第一次玩TopCoder。。。只水题一道。。。

    第一次topcoder,以前老感觉没有资格去做tc,cf什么的,现在已经慢慢接触了. 感觉还可以,还是有让我们这些蒻菜安慰的水题. tc的确很好玩,用客户端比赛,还有各种规则,而且还是只编写一个类提交 ...

随机推荐

  1. hihoCoder 第136周 优化延迟(二分答案+手写堆)

    题目1 : 优化延迟 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho编写了一个处理数据包的程序.程序的输入是一个包含N个数据包的序列.每个数据包根据其重要程度不同 ...

  2. BZOJ3772 精神污染 【主席树 + dfs序】

    题目 兵库县位于日本列岛的中央位置,北临日本海,南面濑户内海直通太平洋,中央部位是森林和山地,与拥有关西机场的大阪府比邻而居,是关西地区面积最大的县,是集经济和文化于一体的一大地区,是日本西部门户,海 ...

  3. java运行时间计算

    long startTime = System.currentTimeMillis(); //获取开始时间 doSomething(); //测试的代码段 long endTime = System. ...

  4. [Codeforces Round #351 Div. 2] 673A Bear and Game

    A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. javaScript防止拦截新窗口打开页面

    原文发布时间为:2009-05-04 -- 来源于本人的百度文章 [由搬家工具导入] 兼容IE.FF.GOOGLE。防止拦截。。。。 <html xmlns="http://www.w ...

  6. 【XPButton类】美化MFC button (转)

    从网上找到别人写的一个XPButton类,利用XPButton类实现XP风格的按钮.百度一下即可找到这个类,接下来具体的步骤如下: 1.创建基于对话框的MFC工程假设命名为:XPButtonTest, ...

  7. Linux signal 那些事儿(4)信号的deliver顺序【转】

    转自:http://blog.chinaunix.net/uid-24774106-id-4084864.html 上一篇博文提到了,如果同时有多个不同的信号处于挂起状态,kernel如何选择deli ...

  8. LeetCode OJ--Palindrome Number

    https://oj.leetcode.com/problems/palindrome-number/ 判断是否为回文数 取每一位存到vector中,再判断 负数不是回文数 class Solutio ...

  9. AC日记——3的幂的和 51nod 1013

    3的幂的和 思路: 矩阵快速幂:   sn-1      3 1        sn   *          = 1     0 1  1 来,上代码: #include <cstdio> ...

  10. HDU——最大连续子序列(区间DP)

    上一个题的加强版! 最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...