资瓷点这里阅读该文章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. 【bzoj4439】[Swerc2015]Landscaping 网络流最小割

    题目描述 FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示) FJ需要对每一行田地从左到右完整开收割机走到头,再对每一列从上到下完整走到头,如下图所示 对于一个4*4的田 ...

  2. XWW的难题(bzoj 3698)

    Description XWW是个影响力很大的人,他有很多的追随者.这些追随者都想要加入XWW教成为XWW的教徒.但是这并不容易,需要通过XWW的考核.XWW给你出了这么一个难题:XWW给你一个N*N ...

  3. pat 团体天梯赛 L2-004. 这是二叉搜索树吗?

    L2-004. 这是二叉搜索树吗? 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一棵二叉搜索树可被递归地定义为具有下列性质的 ...

  4. CF126B password&&HDU 4763 Theme Section

    http://acm.hdu.edu.cn/showproblem.php?pid=4763 http://codeforces.com/problemset/problem/126/B 这两个题都是 ...

  5. Sql常用日期格式

    原文发布时间为:2010-09-16 -- 来源于本人的百度文章 [由搬家工具导入] SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm ...

  6. HTML title属性换行显示的方法

    原文发布时间为:2009-04-22 -- 来源于本人的百度文章 [由搬家工具导入] 解决的方法有两种: 1.将title属性分成几行来写,例如:<a href=#" title=&q ...

  7. [转]在Storyboard中使用自定义的segue类型

    转自:http://my.oschina.net/u/728866/blog/92709 我们知道segue共有三种类型:push.modal以及custom.如下图:   很明显,这三种类型的作用分 ...

  8. LeetCode OJ-- Remove Nth Node From End of List

    https://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/ remove倒数第n个节点 一般list remove node的 ...

  9. 使用Fiddle监听HTTPS网页

    HTTPS相对于HTTP增加了安全性,但是仍然不能有效的防止中间人攻击(Man-in-the-MiddleAttack,简称“MITM攻击”) 这就使得Fiddle工具能够有效的监听HTTPS流量 一 ...

  10. Swoole MySQL 连接池的实现

    目录 概述 代码 扩展 小结 概述 这是关于 Swoole 入门学习的第八篇文章:Swoole MySQL 连接池的实现. 第七篇:Swoole RPC 的实现 第六篇:Swoole 整合成一个小框架 ...