(~ ̄▽ ̄)~*

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; const int MAXN=100005;
char s[MAXN]; int main()
{
int n;
scanf("%d",&n);
scanf("%s",s);//输入01串
int origin=1,flip=0;
for(int i=1;i<strlen(s);i++)
{
if(s[i]==s[i-1])
flip++;//00或11
else origin++;//01或10
}
if(flip>2) flip=2;
//由于不管怎样改变原01串,只有两端关系(可能从11->10/10->11等)会受影响,中间的01串数量仍不变
//所以flip最多就是增加2
printf("%d\n",origin+flip);
}

CF 604C Alternative Thinking#贪心的更多相关文章

  1. CF 115B Lawnmower(贪心)

    题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description ...

  2. CF# 334 Alternative Thinking

    A. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. CF Soldier and Badges (贪心)

    Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心

    C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...

  5. CF Anya and Ghosts (贪心)

    Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. cf 853 A planning [贪心]

    题面: 传送门 思路: 一眼看得,这是贪心[雾] 实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的 那么我们就要最小化sigma(ci*t ...

  7. CF 1082E Increasing Frequency(贪心)

    传送门 解题思路 贪心.对于一段区间中,可以将这段区间中相同的元素同时变成\(c\),但要付出的代价是区间中等于\(c\)的数的个数,设\(sum[i]\)表示等于\(c\)数字的前缀和,Max[i] ...

  8. cf 12C Fruits(贪心【简单数学】)

    题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...

  9. CF 161B Discounts(贪心)

    题目链接: 传送门 Discounts time limit per test:3 second     memory limit per test:256 megabytes Description ...

随机推荐

  1. IOS网络请求中文转码

    -(void)get { NSString *urlStr = @"http://120.25.226.186:32812/login2?username=小码哥&pwd=520it ...

  2. Kali

    http://zydhacker.blog.163.com/blog/static/211795073201447337920/

  3. spring boot maven 插件

    spirng boot 需要使用专用maven插件打包,才能打包.引入如下. <build>        <plugins>            <plugin> ...

  4. 安装用户脚本的福音:Tampermonkey(油猴)

    一直都知道网络的强大,NB的程序员大牛潜伏在我们身边.但是一直以来,如果想使用的一些特殊用途的浏览器插件都无法安装,今天被大神级的师兄给秒到了,原来这世上还有一个免费的用户脚本管理器,有了用户脚本管理 ...

  5. nyoj 592 spiral grid(广搜)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=592 解决以下问题后就方便用广搜解: 1.将数字坐标化,10000坐标为(0,0),这样就 ...

  6. CentOS 6.5 安装MySQL5.7 RPM

    一.新特性 MySQL 5.7可谓是一个令人激动的里程碑,在默认了InnoDB引擎的基础上,新增了ssl.json.虚拟列等新特性.相对于postgreSQL和MariaDB而言,MySQL5.7做了 ...

  7. python 基础篇第一篇

    本节内容 1.python介绍 2.发展史 3.python2和python3 4.安装 5.简单程序,hello world程序 6.变量 7.用户输入 8.模块初识 9..pyc是什么? 10.数 ...

  8. 谷歌游览器对<input type='file'> change只能响应1次解决和样式的改变

    在项目过程中遇到的需要上传本地文件,file的原始控件不太美观,但是这个控件和button有点不太一样, 改变这个样式的思路就是在控件外面套一层链接,然后把file控件的透明度设置为0(透明).样式只 ...

  9. js注入 mooc

    javascript:(function(){try{var a=document.createElement('SCRIPT');a.type='text/javascript',a.src='// ...

  10. Tomcat多域名的配置

    有时候我们有好几个项目需要发布在同一个tomcat服务器上,每个项目有不同的域名.这就需要在tomcat里配置多域名,添加多个虚拟主机. 主要在server.xml里面设置: 在<Engine& ...