Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
2017-03-21 19:11
447 查看
题目链接:http://codeforces.com/contest/625/problem/B
题意:给你s1 s2,你每次操作可以使得s1串中某个字符变成#,然后问你最小修改多少次,就可以使得s1中不含有s2子串
解法:贪心,我们每次修改最后一个字符就好了 这样相交的一定都被修改了
//CF 625B #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 #428 (Div. 2) B. Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- Codeforces Round #277.5 (Div. 2)——C贪心—— Given Length and Sum of Digits
- Codeforces Round #215 (Div. 1) C. Sereja and the Arrangement of Numbers(欧拉图)
- Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man
- Codeforces Round #277.5 (Div. 2)C. Given Length and Sum of Digits...(贪心)
- Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
- Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)
- Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- Codeforces Round #342 (Div. 2)(A)贪心,数学
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
- Codeforces Round #277.5(Div. 2) C. Given Length and Sum of Digits...【贪心】
- Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor【贪心】
- Codeforces Round #177 (Div. 1) C. Polo the Penguin and XOR operation(贪心)
- Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心
- Codeforces Round #377 (Div. 2) Cormen --- The Best Friend Of a Man