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的确很好玩,用客户端比赛,还有各种规则,而且还是只编写一个类提交 ...
随机推荐
- ZOJ 2112 Dynamic Rankings(带修改的区间第K大,分块+二分搜索+二分答案)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- Java众神之路(3)-关键字(上)
关键字(上) 1.final ① 对于基本类型前加以final修饰,表示被修饰的变量为常数,不可以修改.一个既是static又是final的字段表示只占据一段不能改变的存储空间. ② final用于对 ...
- T-SQL百万记录中分组取最大值方法ROW_NUMBER() OVER()
SELECT SysUserID, UserID, ROW_NUMBER() OVER(PARTITION BY UserID ORDER BY AddTime DESC) AS nums AND S ...
- 洛谷 [P3381] 最小费用最大流模版
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- HDU [P3849]
tarjan 求 无向图的割边 (桥) 边 (x,y) 是桥当且仅当, 对于 x 的子节点 y ,low[x] < dfn[y] 对于连向父节点的边要特殊处理 #include <iost ...
- 多核cpu的特殊中断
cpu可以向其他cpu发送中断,也可以向单独某一个cpu发送中断 每个 cpu 都有一个时钟中断源
- Vijos P1404 遭遇战
背景 你知道吗,SQ Class的人都很喜欢打CS.(不知道CS是什么的人不用参加这次比赛). 描述 今天,他们在打一张叫DUSTII的地图,万恶的恐怖分子要炸掉藏在A区的SQC论坛服务器!我们SQC ...
- 原生app与js交互 jsSDK设计
var UA = window.navigator.userAgent.toLowerCase()var isIOS = UA && /iphone|ipad|ipod|ios/.te ...
- 本机开发Native Development:Invalid path for NDK (转)
打开window菜单下的preference选项.选择Android,Native Development(本地开发) 选择你的NDK安装目录.但是,这个插件目前仅支持ndk的r4和r5版本,更高版本 ...
- Python学习杂记_9_集合操作
集合集合是由花括号括起来的一组数据,特点是“数据不重复”,“无序”,“类型不统一”.其中数据不重复是它最重要的特点,常常用于“去重”操作,Set(list)方法可以把列表强制转换成集合. 集合的一些操 ...