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 time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.
Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.
Substring is a continuous subsequence of a string.
Input
The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.
Output
Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.
Sample Input
intellect
tell
Sample Output
1
Hint
题意
给你s1 s2,你每次操作可以使得s1串中某个字符变成#,然后问你最小修改多少次,就可以使得s1中不含有s2子串
题解:
贪心,我们每次修改最后一个字符就好了
这样相交的一定都被修改了
代码
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int main()
{
cin>>s1>>s2;
int ans = 0;
for(int i=0;i<s1.size();i++)
{
int flag = 0;
for(int j=0;j<s2.size();j++)
{
if(i+j>s1.size())
{
flag = 1;
break;
}
if(s1[i+j]!=s2[j])
{
flag = 1;
break;
}
}
if(flag==0)
{
s1[i+s2.size()-1]='#';
ans++;
}
}
cout<<ans<<endl;
}
Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心的更多相关文章
- 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 Round #342 (Div. 2)
贪心 A - Guest From the Past 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...
- Codeforces Round #342 (Div. 2) B
B. War of the Corporations time limit per test 1 second memory limit per test 256 megabytes input st ...
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic 贪心
D. Finals in arithmetic 题目连接: http://www.codeforces.com/contest/625/problem/D Description Vitya is s ...
- Codeforces Round #342 (Div. 2) C. K-special Tables 构造
C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...
- Codeforces Round #342 (Div. 2) A - Guest From the Past 数学
A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...
- Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟
E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)
传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wro ...
随机推荐
- delphi7如何实现 科学计数的转换。 比如我输入2,触发之后会转换成2.000000E+00.求赐教
uses SysUtils; function StrToExp(s: string): string;var f: Extended;begin f := StrToFloat(s); Result ...
- nmon基础
nmon是分析 AIX 和 Linux 性能的免费工具 最简单的安装方式(Ubuntu apt源) sudo apt-get install nmon 在terminal下打开nmon 敲CMD,出现 ...
- Android 者开发如何选择测试机列表
Android 系统已经分化成多种不同的定制版本,制造厂商的不同手机使用的硬件千差万别.差异化带来良好的用户体验的同时,也给开发者带来的适配的问题.于是每个开发团队都需要面临选择测试机列表的问题.我基 ...
- org.unsaved transient instance - save the transient instance before flushing: bug解决方案
最近开发和学习过程中,遇到很多零碎的知识点,在此简单地记录下: 1.遇如下bug: org.unsaved transient instance - save the transient instan ...
- SQL跨数据库复制表数据
SQL跨数据库复制表数据 不同服务器数据库之间的数据操作 不同数据库之间复制表的数据的方法: 当表目标表存在时: insert into 目的数据库..表 select * from 源数据库.. ...
- cocos2d-x CocoStudio中场景触发器(Trigger)的使用和扩展
场景编辑器中的触发器是一种通过事件触发机制,在特定的事件被触发的时候自动执行自己预先定义的动作或者功能. 编辑器中带有一些默认的事件.条件和动作,当然也可以扩展自定义的事件.条件和动作. 触发器可以创 ...
- [Asp.net MVC]Asp.net MVC5系列——Razor语法
Razor视图引擎是Asp.net MVC3中新扩展的内容,并且也是它的默认视图引擎.还有另外一种Web Forms视图引擎.通过前面的文章可知在Asp.net mvc5中创建视图,默认使用的是Raz ...
- Classic Source Code Collected
收藏一些经典的源码,持续更新!!! 1.深度学习框架(Deep Learning Framework). A:Caffe (Convolutional Architecture for Fast Fe ...
- RVM 安装&卸载
安装: curl -L https://get.rvm.io | bash -s stable --autolibs=enabled [--ruby] [--rails] [—trace] $ cur ...
- 扩展UIColor类
在开发中,UI给出的颜色值有时候是十六进制的,有时候给出的是RGB(255,255,255)这样的形式的,而iOS系统提供的方法中并没有直接传递这两种值返回UIColor对象的,这里自己封装了一个以便 ...