暴力匹配+一点判断

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std; const int maxn=+;
char s[maxn];
char t[];
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=; for(int i=;t[i];i++)
{
if(t[i]!=s[i+pos]) {flag=;break;}
}
return flag;
} int main()
{
scanf("%s",s);
scanf("%s",t);
v.clear(); int lens=strlen(s);
int lent=strlen(t); for(int i=;i<lens;i++)
{
if(CMP(i))
{
Seg seg(i,i+lent-);
v.push_back(seg);
}
}
int ans;
if(v.size()==) ans=;
else
{
ans=;
L=v[].l,R=v[].r;
for(int i=;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 ;
}

CodeForces 625B War of the Corporations的更多相关文章

  1. Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心

    B. War of the Corporations 题目连接: http://www.codeforces.com/contest/625/problem/B Description A long ...

  2. hiho 1015 KMP算法 && CF 625 B. War of the Corporations

    #1015 : KMP算法 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在 ...

  3. 【38.02%】【codeforces 625B】War of the Corporations

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  4. War of the Corporations CodeForces - 625B (greed)

    A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue the ...

  5. Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)

    传送门 Description A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Go ...

  6. Codeforces Round #342 (Div. 2)-B. War of the Corporations

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. CodeForces 625B 字符串模拟+思维

    题意 给出字符串a与b 可以将a中的单个字符改为# 问最少改多少次 a中就找不到b了 一开始想的是用strstr 因为如果找到 可以将strstr(a,b)-a+1改成# 即改首字母 用while循环 ...

  8. Codeforces - 625B 贪心

    求最小不重复匹配次数 改最后一个字符最划算 我当时怎么就没看出来.. #include<bits/stdc++.h> using namespace std; string S,T; in ...

  9. Codeforces 625B【KMP】

     题意就是一个串在另一个串出现几次,但是字符不能重复匹配, 比如aaaaaaa aaaa的答案是1 思路: 本来写了个暴力过的,然后觉得KMP改改就好了,就让队友打了一个: #include < ...

随机推荐

  1. JS学习之动态加载script和style样式

    前提:我们可以把一个网页里面的内容理解为一个XML或者说网页本身也就是一个XML文档,XML文档都有很特殊的象征:"标签"也叫"节点".我们都知道一个基本的网页 ...

  2. opencv基础知识------IplImage, CvMat, Mat 的关系和相互转换

    Mat,cvMat和IplImage这三种类型都可以代表和显示图像,但是,Mat类型侧重于计算,数学性较高,openCV对Mat类型的计算也进行了优化.而CvMat和IplImage类型更侧重于“图像 ...

  3. Rar related CMD

    recursively add folder Document to archive: (with all the files) rar a *.rar Document recursively ad ...

  4. excel转化为Json

    Sheet sheet;        Workbook book;        Cell cell1,cell2,cell3,cell4;        JSONArray jsonArray = ...

  5. startActivityForResult与onActivityResult

    androidActivity之间的跳转不只是有startActivity(Intent i)的,startActivityForResult(Intent intent, int requestCo ...

  6. 平移关节(Prismatic Joint)

    package{ import Box2D.Common.Math.b2Vec2; import Box2D.Dynamics.b2Body; import Box2D.Dynamics.Joints ...

  7. 滑轮关节(b2PulleyJoint)

    package{ import Box2D.Collision.b2AABB; import Box2D.Collision.b2RayCastInput; import Box2D.Collisio ...

  8. kvm的live-snapshot

    目前项目中已经存在的快照是针对卷的快照,并且需要关机.所以目前的需求有两个:1.不关机快照:2.针对虚拟机的快照,而不是针对券的快照. 由需求所以针对libvirt做了一些实验,纪录如下: 环境:物理 ...

  9. C#无边框窗体移动 将事件绑定到想实现的控件上

    [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("use ...

  10. PHP开发利器zend studio常见问题解答

    1.如何将zend studio 9的默认GBK编码设置为其它编码,例如UTF-8? 选择window菜单->Preferences->General->Workspace,在界面当 ...