题意

给出一个 N 位的 01 串

然后 每次 改动 可以将其中的 (0 -> 1) 或者 (1 -> 0)

然后 求 最少几次 改动 使得 这个 01 串 当中 不存在 连续的 010 这样的 子串

思路

其实 我们可以发现 连续的 010 子串 有两种情况

第一种: 0101010 这样包含连续的

第二种: 010010 这样 分开的

对于第一种 我们改 两个 1 之间的 0

对于第二种 我们改 两个0 之间 的 1

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll; const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-6; const int INF = 0x3f3f3f3f;
const int maxn = 1e9 + 5;
const int MOD = 1e9 + 7; int main()
{
int n;
string s;
cin >> n >> s;
int m = n - 1;
int ans = 0;
for (int i = 1; i < m; i++)
{
if (s[i] == '1' && s[i - 1] == '0' && s[i + 1] == '0')
{
ans++;
if ((i + 3) <= m && s[i + 2] == '1' && s[i + 3] == '0')
s[i + 1] = '1';
else
s[i] = '0';
}
}
cout << ans << endl;
}

最新文章

  1. mac安装虚拟机
  2. 移动 Web 触摸与运动解决方案 AlloyTouch 开源啦
  3. 关于static/const的作用
  4. Ubuntu的力量何在?
  5. c语言趣味
  6. tlplayer,wzplayer所有平台通用加密测试视频
  7. 【HDOJ】3033 I love sneakers!
  8. 基于Tomcat7、Java、WebSocket的服务器推送聊天室
  9. ReportViewer中设置ServerReport.ReportServerCredentials属性的方法
  10. LNMP优化
  11. SEO策略与细节:细节决定成败
  12. 转:【WebDriver】封装GET方法来解决页面跳转不稳定的问题
  13. vue笔记未整理
  14. 重写 console.log()
  15. 百度地图API的应用
  16. C++获取数组的长度
  17. Django2.0 URL配置
  18. C++11新特性介绍 01
  19. 洛谷P4165 [SCOI2007]组队(排序 堆)
  20. Linux 设备总线驱动模型

热门文章

  1. JS常用正则表达式大全
  2. create table #temptable 临时表 和 declare @bianliang table ()表变量
  3. nightwatch-js ----并发运行
  4. Android开源--PullToRefresh
  5. Hibernate学习之一级缓存
  6. js删除cookie的方法
  7. Google 全球 IP 地址库
  8. Android开发和Android Studio使用教程
  9. 50条SQL查询技巧、查询语句示例
  10. Linux 在不重启的情况下识别新挂载的磁盘