CF 604C Alternative Thinking#贪心
#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#贪心的更多相关文章
- CF 115B Lawnmower(贪心)
题目链接: 传送门 Lawnmower time limit per test:2 second memory limit per test:256 megabytes Description ...
- CF# 334 Alternative Thinking
A. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- CF Soldier and Badges (贪心)
Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心
C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...
- CF Anya and Ghosts (贪心)
Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- cf 853 A planning [贪心]
题面: 传送门 思路: 一眼看得,这是贪心[雾] 实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的 那么我们就要最小化sigma(ci*t ...
- CF 1082E Increasing Frequency(贪心)
传送门 解题思路 贪心.对于一段区间中,可以将这段区间中相同的元素同时变成\(c\),但要付出的代价是区间中等于\(c\)的数的个数,设\(sum[i]\)表示等于\(c\)数字的前缀和,Max[i] ...
- cf 12C Fruits(贪心【简单数学】)
题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...
- CF 161B Discounts(贪心)
题目链接: 传送门 Discounts time limit per test:3 second memory limit per test:256 megabytes Description ...
随机推荐
- 某种数列问题 (一场欢乐赛的T2)
个人觉得挺难的一道DP题 不会 没有思路 于是去找的正解 于是.. #include <iostream> #include <cstring> #define Max 100 ...
- [Q]关于不同比例、不同纸张大小图纸的批量打印
不同比例或不同纸张大小的图纸可以一起批量打印,但目前打图精灵不能自动识别纸张大小,纸张大小是手动指定的,且只能指定一种纸张大小,但设置打印比例为“缩放到可打印区域”或“缩放到纸张边界”仍然可以将不同比 ...
- JS 获取网页的宽高
网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.body.offsetWi ...
- 在vmware workstation10上安装ubuntu14.04,出现以下问题
VMware提示:已将该虚拟机配置为使用 64 位客户机操作系统.但是,无法执行 64 位操作. (1)设置bois 对于HP电脑来说,刚开机时,按住F10,会出现以下界面: 然后回车进行设置: 重启 ...
- OpenGL编译问题随手记
1.error C2381: "exit" : 重定义:__declspec(noreturn) 不同 编译OpenGL Red Book 的例子时出现错误, stdl ...
- linux/windows平台生成随机数的不同方法
linux平台,使用rand.Seed() //rand_linux.go package main import ( "math/rand" "time" ) ...
- asp.net 如何引用dll
这要看你引用dll文件是什么文件,是单纯的类库还是外部或自定义控件dll文件. 如果是类库dll文件,引用的步骤是这样的:在解决方案管理器中,选中要添加引用的项目或网站-右击-添加引用-选择要添加的d ...
- 利用Rsync在windows和linux之间同步数据
使用Rsync从windows同步文件到linux 1.windows服务端的安装与配置: 免费软件下载地址:http://linux.linuxidc.com/,用户名密码为:www.linuxid ...
- unity笔录
----------------------------unity项目在启动splash的时候黑屏 原因不明------------------测试复制项目 用剔除法测试 笔录开始 先用原版本打包 ...
- Java Script 学习笔记
JS编程习惯类: 1. 命名 著名的变量命名规则 只是因为变量名的语法正确,并不意味着就该使用它们.变量还应遵守以下某条著名的命名规则: Camel 标记法 首字母是小写的,接下来的字母都以大写字符开 ...