Codeforces Round #334 (Div. 2) 604C Alternative Thinking(脑洞)

强化学习入门8—深入理解DDPG 本文是强化学习入门系列的第八篇,前面我们讲Actor-Critic时提到了DDPG。DDPG是google DeepMind团队提出的一种用于输出确定性动作的算法,它解决了Actor-Critic 神经网络每次参数更新前后都存在相关性,导致神经网络只能片面的看待问题这一缺点。同时也解决了DQN不能用于连续性动作的缺点。 阅读详情

C. Alternative Thinking
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.

However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and{1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.

Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.

Input

The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).

The following line contains a binary string of length n representing Kevin's results on the USAICO.

Output

Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.

Sample test(s)
input
8
10000011
output
5
input
2
01
output
2
Note

In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.

In the second sample, Kevin can flip the entire string and still have the same score.



题目链接:点击打开链接

给出一个字符串, 可以将连续的0变为1, 问形如"010" "101" "1010"类的字符串最长多长.

若字符串长度小于4, 则字符串最长的长度为字符串本身长度. 否则记录 s[i] != s[i - 1]数量, 加到ans上, ans初始化为3, 因为连续的000可

以变为010, 即长度为3. 最后如果求得的答案大于本身长度, 则答案为字符串本身长度.

AC 代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
int n, ans = 3;
char s[MAXN];
int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    scanf("%s", s);
    for(int i = 1; i < n; ++i)
        ans += (s[i] != s[i - 1]);
    if(ans > n) ans = n;
    printf("%d\n", ans);
    return 0;
}



学习STM32的DS18B20温度传感器 该函数首先复位传感器,然后发送跳过ROM命令和转换命令,并等待转换完成。接下来,它再次复位传感器,发送跳过ROM命令和读取温度命令。最后,它读取温度值的最低字节和最高字节,并将其组合成16位温度值。传感器的VCC引脚连接到STM32的3.3V电源,GND引脚连接到GND,而数据引脚连接到任何一个IO引脚。需要注意的是,示例代码中使用了一个简单的延时函数来等待转换完成。实际上,您可能需要使用定时器或其他更精确的延时方法来实现更准确的延时。下面是一个示例代码,演示如何读取DS18B20传感器的温度值。 阅读详情

相关推荐

Arduino——GY39大气压、温湿度、光照模块

前几天买东西的时候买了一个GY39,这个模块集成了温湿度,大气压,海拔,光照一体,使用起来很方面。它有两种工作模式使用串口模式时需要搭配转接板,我选择了IIC模式,看一下通信协议吧,就是关于高八位和低八位的数据。看一下接线。

戚晨夕的博客 2604

Codeforces 603A Alternative Thinking(字符串规律)

@(K ACMer)题意: 给你一个01字符串,你必须翻转其中的一个子串,问执行该操作后该字符串的最长交替子序列长度为多少? 分析 首先显然翻转整个字符串该字符串的01子序列长度不变,所以最次也是不变不会减小 然后我们队字符串进行压缩把连续的0和,连续的1压缩为一个,并记录它们各自压缩前的连续字符的个数。 显然交替子序列的个数最多增加两个,我们定义"00","11"这样的字符串叫做对。发现

JIBANCANYANG 1069

pgsql:还原数据库后出现重复序列导致“more than one owned sequence found“报错问题的解决

pgsql数据库通过备份数据库文件进行还原时,如果表中有自增序列,还原后可能会出现重复的序列,此时若向表中插入新行时会出现“more than one owned sequence found”的报错提示。还原数据库时把序列取消勾选,选择不还原序列。因为还原表的同时,会自动将自增序列还原上去,此处勾选会导致数据库重复创建序列。点击还原数据库完毕后,可以看到序列仅有一个,没有出现重复序列。但此时的序列当前值是从1开始的,需要重置。点击菜单“其它”-》“序列”,可以看到有多个重复序列。

奋斗鱼 1043

CodeForces 604C Alternative Thinking(思维题)

题目链接:点击打开链接 题意:给出01字符串。可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所有的位取反。求经过处理后最多会得到多少次01变换(可以不连续)。 思路:思维题。模拟可以发现,增加01变换的方式有大致三种,一是在连续相同的字符串(这种子串记为s)内部找子串取反,这种能够增加01变换的s长度要大于等于3,如10001->10101;二是在s与其相邻非s取相应的部分取反,如

不忘初心 487

SUMO仿真教程(1) ——安装环境的设置(Windows 10系统)

SUMO安装环境的设置 目录一.SUMO下载的官方网址二.下载步骤:三.环境设置:1.打开设置环境变量的界面2.用户(Administrator)变量设置3.系统变量设置四.总述 一.SUMO下载的官方网址 sumo的下载地址: 二.下载步骤: 1.以sumo1.8.0为示例进行演示,点击下载地址; 2.选择Windows64位的安装版本,如下图所示: 3.点击对应版本会跳转到如下图所示的界面,等待几秒后会自动下载(温馨提示:请将下载路径提前设置好): 4.到目标存储路径下查看下载完成的SUMO(本

weixin_50632459的博客 1万+

ISCC-Amy‘s Code CTF-Reverse

ISCC-Amy's Code CTF-Reverse

m0_72904009的博客 682

codeforces604C Alternative Thinking (脑洞大开 )

题目连接:http://codeforces.com/contest/604/problem/C  C. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standar

hkh746392783的专栏 1013

20220601超简单百度地图街景图片爬取+绿视率计算

真的不难咯。

weixin_39676904的博客 1万+

CodeForces 603A Alternative Thinking 题解

【题目大意】: 给你一个字符串,你可以使得某一个连续的01串翻转过来(将0变1,1变0),问最长的01相隔的子序列(可不连续,关于不连续可见样例)的长度为多少(原题及样例见下) Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes inp

初学者 1646

CTR-GCN 论文解读

提出了一种信道拓扑优化图卷积,该卷积可以动态有效地对信道拓扑进行建模。共享拓扑是一个参数化的邻接矩阵,作为所有通道的拓扑先验,并提供顶点之间的一般相关性。通过使用特定于通道的相关性细化共享拓扑,CTR-GC 获得了通道拓扑。

一杯水果茶!足矣~ 3088

全国青少年信息素养大赛图形化(Scratch)编程考点总结

全国青少年信息素养大赛图形化(Scratch)编程考点总结

伶俐角少儿编程 382

Codeforces 604C - Alternative Thinking(思维)

C. Alternative Thinking time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Kevin has just recevied his disappointing results on the USA Ident

Snakeflute的博客 802

innovus:如何在init design之后新增参考库(lib/lef)

如题,在PR过程中经常会遇到这种问题,时序无法收敛,需要新增一套lvt或者hpc的库,怎么办?

m0_61544122的博客 5005

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

题目链接:http://codeforces.com/contest/604/problem/C 大致题意:给定一个01串以及其长度,求此串中符合形如“0101“或”101“这种01交错的序列(不必连续)的长度,并且你可以选定这个串中1段连续的子串进行反转(将0反转为1,将1反转为0),力求反转之后的串中所符合题意的序列的长度最大,并输出其长度。 (题目中”he decides that he...

weixin_30376509的博客 70

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

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

C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/problem/C Description Kevin has just recevied his disappointing results on the USA Identifi...

weixin_34072458的博客 185

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Alternative Thinking CodeForces - 604C(思维)

Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's sc

SunMoonVocano的博客 424

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Codeforces 604 C Alternative Thinking【思维】

C. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin has just recevied his disappointing results on the

mengxiang000000 1329

【Codeforces Round 334 (Div 2)C】【脑洞】Alternative Thinking 最多反转一个区间使得最长跳跃子串的长度尽可能长

Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin has just recevied his disappointin

snowy_smile的博客 987

Alternative Thinking

Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's sco

海绵的博客 405

D - Alternative Thinking

Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's sco

philophobia的博客 483

CodeForces 603A Alternative Thinking

A. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin has just recevied his disappointing res

lizhaowei213的博客 985

Codeforces Round #334 (603A) Alternative Thinking [贪心]

Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. —— 给出一个01串,先在你可以取反其中一个Substring(0变1,1变0),问这样操作后最长的0,1间隔子序列最长是多少。

Asuna_acmer 888

Alternative Thinking(CodeForces - 604C)(思维)

Alternative Thinking(CodeForces - 604C)Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the

reset的博客 531

Codeforces Round #334 (Div. 1)

自从CF的rating改版以后终于回到DIV1了。打了一场还比预期好,如果C题不错的话应该可以继续上分,可惜了。 Codeforces 603A. Alternative Thinking 题目链接:http://codeforces.com/problemset/problem/603/A 题意:给你一个01串,要你选择其中一个非空的01子串,将其反转(0变成1,1变成0),要

Fry_guest的专栏 1222

Codeforces Round #334 (Div. 1) ABC

A Alternative Thinking         贪心。从左到右扫,找到最先出现的 和上个字符相同的 字符(连续的11或00)。从这个字符开始,只要它和上个字符相同,就反转,再往后考察,反转尽量多,直到字符相异时停止。最后统计一下即可。 #include using namespace std; #define ll long long char str[100010]

A Cube Master 717

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

C. Alternative Thinking time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kevin has just recevied his disappo

走一步再走一步 710
上一篇: Educational Codeforces Round 2 600C Make Palindrome(脑洞)
下一篇: Codeforces Round #334 (Div. 2) 604D Modular Arithmetic(数学+快速幂)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值