2017美团编程大赛初赛B-E.子串(进制转换+KMP)
2017-06-25 18:34
225 查看
记录一个菜逼的成长。。
没什么好说的。。就是暴力。
没什么好说的。。就是暴力。
#include <stdio.h> #include <math.h> #include <assert.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <deque> #include <bitset> #include <algorithm> using namespace std; #define ALL(v) (v).begin(),(v).end() #define cl(a,b) memset(a,b,sizeof(a)) #define clr clear() #define pb push_back #define mp make_pair #define fi first #define se second const int maxn = 1000000 + 1; char str[16][maxn],s[maxn]; int _next[maxn]; void getNext(char *p,int len) { int i = 0, j = -1; _next[i] = j; while(i < len){ if(j == -1 || p[i] == p[j]){ ++i,++j; if(p[i] != p[j])_next[i] = j; else _next[i] = _next[j]; } else j = _next[j]; } } int KMP(char *s,char *p) { int i = 0, j = 0; int cnt = 0; int n = strlen(s),m = strlen(p); getNext(p,m); while(i < n &&j < m){ if(j == -1 || s[i] == p[j]){ i++;j++; } else j = _next[j]; if( j == m){ cnt++; j = _next[j]; } } return cnt; } int main() { int n; while(~scanf("%d%s",&n,s)){ int k = 0; for( int i = 0; s[i]; i++ ){ if(isd 4000 igit(s[i])){ k = max(k,s[i] - '0'); } else { k = max(k,s[i] - 'A' + 10); } } int c = 0; for( int i = k + 1; i <= 16; i++,c++ ){ int len = 0; for( int j = 1; j <= n; j++ ){ int tmp = j,cnt = 0; char ss[100]; while(tmp){ ss[cnt++] = (tmp % i < 10 ? tmp % i + '0' : tmp % i - 10 + 'A'); tmp /= i; } for( int p = cnt-1; p >= 0; p-- ) str[c][len++] = ss[p]; } str[c][len] = '\0'; } for( int i = 0; i < c; i++ ){ if(KMP(str[i],s))return 0*puts("yes"); } puts("no"); } return 0; }
相关文章推荐
- (CodeM美团点评编程大赛初赛B轮)子串(kmp+暴力)
- CodeM美团点评编程大赛初赛B轮 E.子串【暴力模拟+KMP】水题
- CodeM美团点评编程大赛 初赛B轮 A 黑白树 贪心 E 子串 暴力
- CodeM美团点评编程大赛初赛A轮 B.合并回文子串【区间Dp】
- 2017美团编程大赛初赛A-C.倒水
- 2014第六届华为创新杯编程大赛初赛解题报告
- csdn 英雄会第四届在线编程大赛·线上初赛:带通配符的数
- CSDN英雄会第四届在线编程大赛·线上初赛:带通配符的数
- CodeM美团点评编程大赛初赛B轮 B.送外卖2 三进制状压DP
- 第五届华为“创新杯”编程大赛初赛题目(第二场)
- 英雄会第四届在线编程大赛·线上初赛:带通配符的数
- CodeM美团点评编程大赛初赛A轮 数列互质
- CodeM美团点评编程大赛初赛B轮 A.黑白树【树型Dp】
- csdn英雄会题解之第五届在线编程大赛月赛指定题目:反向互补子串
- 英雄会第四届在线编程大赛·线上初赛:带通配符的数
- 2013华为第五届编程大赛 成都初赛题目和解答
- 【结果发布】第六届SeedCoder编程大赛初赛结果发布
- csdn第四届在线编程大赛·线上初赛:带通配符的数
- 2005年Goole编程大赛初赛题目二(750分)
- codeM美团编程大赛初赛B轮E题