Codeforces Round #336 (Div. 1) C. Marbles
来源:互联网 发布:fm 迭戈科斯塔数据 编辑:程序博客网 时间:2024/06/11 09:05
题意很好理解
方法是从codeforce的博客上学来的点击打开链接
也很容易证明
然后就是怎么求串a的后缀和串b的前缀是否有相等的
只用kmp扫一遍就好了
真是机智啊!!!
自己想不到
#include <bits/stdc++.h>using namespace std;#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }typedef long long LL;const int oo = 0x3f3f3f3f;const int maxn = 1000000;int n;char a[maxn + 5], b[maxn + 5];int nxt[maxn + 5];int main(){scanf("%*d");scanf("%s%s", a, b);n = strlen(a);REP(i, 0, n){if (a[i] == 'N') a[i] = 'S';else if (a[i] == 'S') a[i] = 'N';else if (a[i] == 'E') a[i] = 'W';else if (a[i] == 'W') a[i] = 'E';}reverse(b, b + n);//倒置函数 nxt[0] = 0, nxt[1] = 0;int i = 1, j = 0;while (i < n){while (j && b[i] != b[j]) j = nxt[j];if (b[i] == b[j]) ++j;++i;nxt[i] = j;}int cur = 0;REP(i, 0, n){while (cur && a[i] != b[cur]) cur = nxt[cur];if (a[i] == b[cur]) ++cur;}puts(cur ? "NO" : "YES");return 0;}
0 0
- Codeforces Round #336 (Div. 1) C. Marbles
- 【DP】Codeforces Round #336 (Div. 2) C
- 【dp】Codeforces Round #110 (Div. 1) C
- Codeforces Round #142 (Div. 1) C. Triangles
- Codeforces Round #230 (Div. 1)B,C
- Codeforces Round #259 (Div. 1)C题
- Codeforces Round #228 (Div. 1) C 贪心
- Codeforces Round #284 (Div. 1) C
- Codeforces Round #286 (Div. 1) C、D
- Codeforces Round #302 (Div. 1) C
- Codeforces Round #333 (Div. 1) C
- Codeforces Round #356 (Div. 1) C
- Codeforces Round #362 (Div. 1) C PLEASE
- Codeforces Round #363 (Div. 1) C LRU
- Codeforces Round #363 (Div. 1) C LRU
- Codeforces Round #364 (Div. 1) C
- Codeforces Round #372 (Div. 1) C
- Codeforces Round #381 (Div. 1) C
- ImageSwitcher的用法
- QNAP NAS 搭建SVN服务器笔记
- Tomcat配置Server.xml文件,映射磁盘资源
- PHPstorm的快捷方式
- Linux USB 驱动开发(二)—— USB 驱动几个重要数据结构
- Codeforces Round #336 (Div. 1) C. Marbles
- 35. Search Insert Position
- Java反射机制浅谈
- Python学习:异步IO:协程和asyncio
- vim配置收藏
- Codeforences Educational Round10 C. Foe Pairs
- android ViewPager滑动事件
- kokodudu的专栏之malloc函数的用法
- poj2985The k-th Largest Group