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, 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的更多相关文章
- 1Z0-053 争议题目解析541
1Z0-053 争议题目解析541 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 541.If you use ALTER DISKGROUP ... ADD DISK and s ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- SRM 513 2 1000CutTheNumbers(状态压缩)
SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...
- SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)
SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...
- SRM 657 DIV2
-------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...
- [RabbitMQ] AMQP close-reason, initiated by Library, code=541
RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachabl ...
- 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 ...
- TC srm 673 300 div1
TC srm.673 300 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 Description 给你n(n<=50)匹马和n个人,一匹马和一个人能 ...
- SRM 584 第一次玩TopCoder。。。只水题一道。。。
第一次topcoder,以前老感觉没有资格去做tc,cf什么的,现在已经慢慢接触了. 感觉还可以,还是有让我们这些蒻菜安慰的水题. tc的确很好玩,用客户端比赛,还有各种规则,而且还是只编写一个类提交 ...
随机推荐
- POJ 1753 Flip Game(高斯消元+状压枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45691 Accepted: 19590 Descr ...
- 流浪者(rover)
流浪者(rover) 题目描述 有一位流浪者正在一个n∗mn∗m的网格图上流浪.初始时流浪者拥有SS点体力值. 流浪者会从(1,1)(1,1)走向(n,m)(n,m),并且他只会向下走((x,y)→( ...
- 在子页面session过期无法跳转到父页面
当session过期后可以用过滤器来设置重定向页面 public class ActionFilter extends HttpServlet implements Filter { private ...
- codechef May Challenge 2016 LADDU: Ladd 模拟
All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russia ...
- service中显示一个dialog
dialog是依附于activity存在的.但是app中经常需要使用以下的情况,在service中做一些后台操作,在某个临界条件满足时,显示一个dialog告知用户.这时dialog无法直接从serv ...
- Python之数据结构:元组
一.元组 tupleA=(1,2,3,4,5,6) print tupleA 1.元组支持的运算符 tup1+tup2 tup1*2 3 in tup2 for i in tup2: print i ...
- EasyUI中combogrid设置onSelect后 获取不到getSelecte问题解决
$('#person').combogrid({ onSelect: function(index, item){ $('#dataForm').form('load', item); $(" ...
- 【虚拟机】主机与VMware虚拟机通信(XP版)(转)
一.与主机共享ADSL链接/无线网络(虚拟机内可上网) 安装虚拟机后,在网络链接下除了本地链接外,会出现两个新的链接,分别是VMware Network Adapter VMnet1和VMware N ...
- Java反射获取类对象的三种方式
package demo01; /* * 获取一个类的class文件对象的三种方式 * 1.对象获取 * 2.类名获取 * 3.Class类的静态方法获取 */ public class Reflec ...
- C#使用SSDB管理增量日志并提供查询
Program.cs using System; using System.Text; using CommonLinkLibrary.Util; using Newtonsoft.Json; nam ...