题目链接
题意:给定一个01数量相等的二进制字符串,每次操作可以旋转一段子串,问至少多少次操作可以使得所有相邻字符都不一样。
思路:对于某个"00"开头(结尾),"11"结尾(开头)的子串,可以在一次操作完成置换,所以答案就是字符串中"00"或者"11"的数量的最大值,将其与整个字符串的开头或结尾配对即可。
AC代码:

#include <bits/stdc++.h>
#define pcc pair<char, char>
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for (int i = x; i < y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
#define rep0(i, n) for (int i = 0; i < (n); i++)
#define per0(i, n) for (int i = (n)-1; i >= 0; i--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
using namespace std;inline int read() {int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9') {if (ch == '-') f = -1;ch = getchar();}while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';ch = getchar();}return x * f;
}const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 6e6 + 10;
const int MAX = 1e5;
const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f;
ll qpow(ll a, ll b) {ll res = 1;while (b) {if (b & 1) res = (res * a) % mod;a = (a * a) % mod;b >>= 1;}return res % mod;
}
/***************main****************/
ll T = 1;
ll m, n;
int main() {T = read();while (T--) {n = read();int ans[2] = {0, 0};string s;cin >> s;rep(i, 1, n) if (s[i] == s[i - 1]) ans[s[i] - '0']++;cout << max(ans[0], ans[1]) << endl;}return 0;
}

CF- Educational Codeforces Round 97 (Rated for Div. 2)-1437B. Reverse Binary Strings【思维/贪心】相关推荐

  1. Educational Codeforces Round 73 (Rated for Div. 2) E. Game With String 思维博弈 好题(2500)

    传送门 文章目录 题意: 思路: 题意: 思路: 我们将每一段...拿出来看成若干段,将其分成以下四种情况: (1)len<b(1)len<b(1)len<b (2)b≤len< ...

  2. cf Educational Codeforces Round 85 (Rated for Div. 2)B. Middle Class

    题目链接:https://codeforces.com/contest/1334/problem/B B. Middle Class time limit per test2 seconds memo ...

  3. Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies 【贪心 】

    传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds ...

  4. Educational Codeforces Round 96 (Rated for Div. 2) C. Numbers on Whiteboard///思维

    cf地址 题目大意:给一个数n,有1~n的数,每次现在两个数a,b,将这两个数去掉,然后添加一个(a+b)/2的数(向上取整),进行n-1次操作后,问你最后剩下的数最小是多少. 思路:最小的数必定为2 ...

  5. Educational Codeforces Round 77 (Rated for Div. 2) D. A Game with Traps 贪心 +二分

    传送门 文章目录 题意: 思路: 题意: 给你nnn个人,每个人都有个能力值aia_iai​.让后在1−m1-m1−m的路上有kkk个陷阱,每个陷阱的范围是[li,ri][l_i,r_i][li​,r ...

  6. Educational Codeforces Round 101 (Rated for Div. 2) C. Building a Fence 思维取范围

    传送门 题意: 思路: 刚看到这个题其实是没什么思路,想过从前往后推或者从后往前推,但是都不是很可行.因为两边都有一个固定的挡板挡住,我们可以根据其中的一个算出来每个位置高度的范围,让后检查一下范围是 ...

  7. Educational Codeforces Round 101 (Rated for Div. 2) D. Ceil Divisions(思维)

    给出数 n ,数组 a 为 {1,2,3,--n},最多有 n+5 次机会,将任意两个不相等的数做  ceil(x/y) 运算,使得最后的数组 a 只有一个 2,其余全为 1,给出运算次数具体的运算步 ...

  8. Educational Codeforces Round 96 (Rated for Div. 2)C. Numbers on Whiteboard(贪心算法(水题))

    题目链接: 传送门 题目贴上: 题意:,给你 1-n个数,你可以对两个不同位置的数进行合并,比如a和b,合成数变成(a+b)/2,结果四舍五入.放在数组末尾,删除原来的a和b,举例子吧 就这样子两两合 ...

  9. 【CF比赛】Educational Codeforces Round 102 (Rated for Div. 2)

    题目来源 Educational Codeforces Round 102 (Rated for Div. 2) A. Replacing Elements 只要判断最大值是否小于等于d,或者第一个值 ...

最新文章

  1. 【PAT乙级】1032 挖掘机技术哪家强 (20 分)
  2. C++——《算法分析与设计》实验报告——单源最短路径问题
  3. VTK:Remote之FrenetSerretFrame
  4. spring bean初始化及销毁你必须要掌握的回调方法。
  5. Android消息队列图片记录
  6. django 定制admin
  7. 文件上传fileupload文件接收
  8. ARFoundation系列讲解-教程目录
  9. php汉字utf8编码转换,PHP UTF8编码内的繁简转换类
  10. 华为机试4.20:新员工考试
  11. 【数据结构】二叉树经典习题
  12. sample函数—R语言
  13. #####好好好好######Neo4j 第三篇:Cypher查询入门
  14. 1919: 三个整数排序(指针专题)
  15. 第六周作业——百词斩扇贝单词背单词功能模块测试
  16. 免费申请Jetbrains的产品
  17. Java基础-面试题精华(2021最新)
  18. 什么造就了中国的XP系统依赖症
  19. AUC(一):AUC与Mann–Whitney U test
  20. html 一键复制 ios,兼容安卓和ios实现一键复制内容到剪切板

热门文章

  1. Github fow Windows 安装问题
  2. 吴恩达深度学习笔记——卷积神经网络(Convolutional Neural Networks)
  3. 计算机教育及课程总结报告,信息技术教学工作总结范文
  4. 六月集训(第20天) —— 二叉搜索树
  5. 如何填写项目商业论证
  6. VB6.0中没有ADO控件该如何办???
  7. 阿里云出事了,被工信部处罚,它真不冤,但也别慌
  8. 我编写的俄罗斯方块源代码,支持单机对战,可定制方块数,键盘等!!! (转)
  9. JavaScript初学-入门前端小游戏-超简单
  10. AUTOSAR CAN Dirver模块说明及ETAS ISOLAR A/B配置(1)--概述和功能描述