CodeForces 625B War of the Corporations
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces 625B War of the Corporations相关的知识,希望对你有一定的参考价值。
暴力匹配+一点判断
#include <stdio.h> #include <algorithm> #include <string.h> #include <queue> #include <stack> #include <map> #include <vector> using namespace std; const int maxn=100000+50; char s[maxn]; char t[35]; struct Seg { int l,r; Seg(int a,int b){l=a;r=b;} }; vector<Seg>v; int L,R; bool CMP(int pos) { bool flag=1; for(int i=0;t[i];i++) { if(t[i]!=s[i+pos]) {flag=0;break;} } return flag; } int main() { scanf("%s",s); scanf("%s",t); v.clear(); int lens=strlen(s); int lent=strlen(t); for(int i=0;i<lens;i++) { if(CMP(i)) { Seg seg(i,i+lent-1); v.push_back(seg); } } int ans; if(v.size()==0) ans=0; else { ans=1; L=v[0].l,R=v[0].r; for(int i=1;i<v.size();i++) { if(v[i].l<=R) L=v[i].l; else { ans++; L=v[i].l; R=v[i].r; } } } printf("%d\n",ans); return 0; }
以上是关于CodeForces 625B War of the Corporations的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)
Educational Codeforces Round 7 F - The Sum of the k-th Powers 拉格朗日插值
Codeforces 622F The Sum of the k-th Powers
codeforces 622F. The Sum of the k-th Powers 拉格朗日插值法
The Sum of the k-th Powers()Educational Codeforces Round 7F+拉格朗日插值法)