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=+;
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的更多相关文章
- 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 ...
- hiho 1015 KMP算法 && CF 625 B. War of the Corporations
#1015 : KMP算法 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在 ...
- 【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 ...
- 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 ...
- 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 ...
- Codeforces Round #342 (Div. 2)-B. War of the Corporations
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- CodeForces 625B 字符串模拟+思维
题意 给出字符串a与b 可以将a中的单个字符改为# 问最少改多少次 a中就找不到b了 一开始想的是用strstr 因为如果找到 可以将strstr(a,b)-a+1改成# 即改首字母 用while循环 ...
- Codeforces - 625B 贪心
求最小不重复匹配次数 改最后一个字符最划算 我当时怎么就没看出来.. #include<bits/stdc++.h> using namespace std; string S,T; in ...
- Codeforces 625B【KMP】
题意就是一个串在另一个串出现几次,但是字符不能重复匹配, 比如aaaaaaa aaaa的答案是1 思路: 本来写了个暴力过的,然后觉得KMP改改就好了,就让队友打了一个: #include < ...
随机推荐
- 【servlet】 过滤器模板
EncodingFilter.java package Filter; import java.io.IOException; import javax.servlet.Filter; import ...
- servlet & javabean
1.servelet 什么是Servlet?① Servlet就是JAVA 类② Servlet是一个继承HttpServlet类的类③这个在服务器端运行,用以处理客户端的请求 Servlet相关包的 ...
- jenkins tags
List Subversion tags (and more) 参数设置 Tags filter ^((?!_ta_).)*$ 表示不含_ta_ Tags filtertrunk|(tags|bran ...
- redis 工具类 单个redis、JedisPool 及多个redis、shardedJedisPool与spring的集成配置
http://www.cnblogs.com/edisonfeng/p/3571870.html http://javacrazyer.iteye.com/blog/1840161 http://ww ...
- Chapter 1 First Sight——9
One of the best things about Charlie is he doesn't hover. 一件最好的事是查理兹他不在附近. He left me alone to unpac ...
- java工程开发之图形化界面之(第二课)
上一节主要是讨论小的应用程序,在这里我们将采用一种全新的方式来重新编写它. 在这里我们注重关注JFrame和JOptionPane.这些类提供了在JAVA应用程序使用图形的方法以及在JAVA程序中对I ...
- 配置Eclipse支持java和xml文件的代码补全功能
百度经验:jingyan.baidu.com 本文介绍如何配置Eclipse,使得在编写代码时无论是*.java还是*.xml文件都能够通过使用ALT+/快捷键实现代码不全的功能. 本文实验环境为:W ...
- angularJS 系列(六)---$emit(), $on(), $broadcast()的使用
下面以一个例子来讲述 angular 中的event system,有$emit(), $on(), $broadcast().效果图如下 下面的代码中,用到了 controller AS 的语法,具 ...
- HDU 1887 Weird Numbers(负数的进制转化)
题目要求有两种情况,第一种from情况,正常输出即可,很简单.第二种是to情况,给一个数字,输出负进制R的原码,这个有点小麻烦...解决方法如下; 首先,把这个数n按正常方式展开,形式如下: .... ...
- linux安装安卓开发工具android studio
http://www.android-studio.org/ http://android-studio.org/index.php/docs/guide 最近要接触android编程,本来想装ecl ...