Codeforces Round #163 (Div. 2) / 226A Stones on the Table (字符串处理)

保姆级教程:用Wokwi玩转ESP32 MicroPython仿真(含库文件配置指南) 本教程详细介绍了如何使用Wokwi平台进行ESP32 MicroPython仿真开发,包括库文件配置、传感器数据模拟和REPL调试技巧。通过Wokwi的仿真调试系统,开发者可以在浏览器中快速验证代码逻辑,提高开发效率,特别适合物联网项目的快速迭代。 阅读详情

A. Stones on the Table
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.

Input

The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table.

The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals "R", if the i-th stone is red, "G", if it's green and "B", if it's blue.

Output

Print a single integer — the answer to the problem.

Sample test(s)
input
3
RRG
output
1
input
5
RRRRR
output
4
input
4
BRBG
output
0

题意:一列的石子有三种颜色,取出x个,剩下的石子相邻间颜色不同,求min(x)。


完整代码:

/*30ms,0KB*/

#include <cstdio>

int main()
{
	int n, count = 0;
	scanf("%d", &n);
	getchar();
	char now = getchar(), ch;
	while (--n)
	{
		ch = getchar();
		if (ch == now)
			++count;
		else
			now = ch;
	}
	printf("%d", count);
	return 0;
}


一篇NS SAR ADC的学习记录 一篇NS SAR ADC的学习记录 内容包含: OverSampling Noise Shaping Dynamic Amplifier DAC with Redundancy 最近看了些有意思的SAR ADC结构,但是因为确实对模拟这个领域不太熟,导致了一系列的级联查找,最终达到了一个大概能懂的状态,为了理清思路,顺便别让看了这么些天的东西浪费了,还是计划写篇文章。 ps:由于不是一篇特别正紧的报告,参考文献就写的比较随便,且我还是个做数字的 A 13.5-ENOB, 107-μW Noise-Sha 阅读详情

相关推荐

避开RK3588开发板SDIO配置的坑:O9201SB WiFi模组接入实战指南

本文为嵌入式开发者提供了在RK3588开发板上,利用TF卡槽接入O9201SB WiFi6模组的实战指南。文章深度剖析了SDIO配置中常见的电源管理序列冲突问题,并给出了从设备树节点修改、内核编译到系统验证的完整解决方案,帮助开发者避开配置陷阱,成功实现高性能无线连接。

sprite的博客 954

codeforces 266A Stones on the Table(模拟水题)

A. Stones on the Table 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n stones on the table in a

1669

【通信协议】I2C总线(一主多从)

I2C总线(一主多从)之软件模拟代码详解

m0_75090944的博客 9840

CodeForces - 266A Stones on the Table 【水题】

** CodeForces - 266A Stones on the Table 【水题】 ** 266A Stones on the Table Problem Description There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum num...

weixin_43337555的博客 881

先进封装Interposer仿真步骤及说明

摘要: Interposer仿真是2.5D/3DIC封装设计的关键环节,涵盖信号完整性(SI)、电源完整性(PI)、热及结构应力分析。流程分为五个阶段:1)前处理,定义层叠结构与材料属性;2)参数提取,通过3D电磁建模获取TSV、传输线等寄生参数;3)仿真设置,选择求解器并设定频率范围;4)结果分析,评估信号损耗、阻抗及电源网络性能;5)后处理,进行多物理场协同仿真并生成模型。核心挑战在于多尺度与多物理场耦合,需优先确保高速信号与电源网络的仿真精度。常用工具包括Ansys HFSS、Cadence Sigr

DSY_0324的博客 1346

E4A蓝牙APP开发实战:从零到一构建简易物联网控制终端

本文详细介绍了使用E4A(易安卓)开发蓝牙APP的实战教程,从零开始构建简易物联网控制终端。通过E4A的中文编程环境和内置蓝牙组件,开发者可以快速实现智能家居控制、创客项目遥控等功能。文章涵盖硬件准备、开发环境搭建、核心代码解析及典型应用场景,特别适合零Java基础的电子爱好者入门蓝牙APP开发。

weixin_42715608的博客 474

Stones on the Table(CodeForces-266A)

A. Stones on the Table time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n stones on the table in a row, each of them can be red, gree...

lvy_yu_ET的博客 411

逆向攻防世界CTF系列40-ReverseMe-120

注意sub_401000main中只传了两个参数,但是跟进后发现四个(可能是隐式传递,放在寄存器里传递了),调试发现a4是输入长度,与最终的you_know_how_to_remove_junk_code比较的是v12(但是并没有被传入),开始怀疑是不是隐式传递了。_mm_xor_si128用于计算128位(16字节)的按位异或,然后通过v14控制循环结束的条件,可以看到v14增长的步长为16,而且通过上面得到的flag值解码得到的字符串为32个字节大小,正好是16的整数倍。

LH1013886337的博客 1410

CodeForces 266A Stones on the Table

Stones on the Table Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u SubmitStatusPracticeCodeForces 266A Description There are n stones on the table in a row,

花花的笔记 1124

PowerDesigner 数据库建模使用详解

PowerDesigner 数据库建模使用详解

congge 7082

【Unity实战篇 】| 游戏中实现镂空遮罩效果【矩形、圆形镂空遮罩】

本文来写一下怎样在Unity中完成一个 镂空遮罩 的效果。 镂空遮罩 比较常用的有两种:矩形镂空遮罩、圆形镂空遮罩。 镂空遮罩 在游戏中常被当做新手引导必备的内容,可以给玩家更多不一样的体验。 下面就一起来看一下怎样做出这种效果吧!

努力前行,总会成为自己心中的那道光 1万+

Problem--266A--Codeforces--Stones on the Table

Stones on the Tablestime limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n stones on the table in a row, each of them can be red, gre

qq_36667106的博客 683

CAN总线介绍及硬件设计

1. CAN是什么 CAN 是 Controller Area Network 的缩写(以下称为 CAN),是 ISO*1 国际标准化的串行通信协议。 在当前的汽车产业中,出于对安全性、舒适性、方便性、低公害、低成本的要求,各种各样的电子控制系统 被开发了出来。由于这些系统之间通信所用的数据类型及对可靠性的要求不尽相同,由多条总线构成的情况很 多,线束的数量也随之增加。为适应“减少线束的数量”、“......

sinat_15677011的博客 9991

Codeforces Round #163 (Div. 2)A. Stones on the Table

There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Sto...

轻舟载君不载愁 184

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Codeforces Round #163 (Div. 2) A. Stones on the Table

题目:http://www.codeforces.com/contest/266/my 思路:模拟法 #include <iostream> using namespace std; char arr[55]; int main() { int n; cin>>n; for(int i=0;i<n;i++)...

weixin_34234823的博客 239

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

[Codeforces Round #163 (Div. 2)]A. Stones on the Table

地址:http://codeforces.com/contest/266/problem/A 可以看作是记录连续重复序列的长度和 1 #include<stdio.h> 2 3 int n; 4 char in[55]; 5 6 int main() 7 { 8 int i,count=0; 9 scanf("%d",&am...

weixin_30621959的博客 137

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

CodeForces-266A Stones on the Table(语法练习题)

Stones on the Table time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n stones on the table in a row, each of them can be red, green o...

weixin_43939327的博客 223

小白题解 Codeforces 266A Stones on the Table

小白题解 Codeforces 266A Stones on the Table (LIS问题经典变形)题目链接:点击打开链接 题目大意:给定一排只有三种颜色的n个石头,要求移除掉尽可能少的石头使两两相邻的石头颜色都不同。 分析:这道题目可以从移除以后的结果进行分析,不难想象,最优解一定是原来排列的“最长不同子序列”。则可以用LIS模板进行编码。另外由于n只有50,则用最朴素的O(n*n)算法即可。好啦,下面是AC代码(另附上该种算法的LIS模板一份)。

Talk is cheap,give me the code! 477

水题 codeforces 266A Stones on the Table (i--)

水题 很简单 但是没有一发过 记录下来 思路:直接遍历一遍即可 code: #include<iostream>#include<stdio.h>#include<string>#include<algorithm>#include <iterator>#include<queue>#include<functio...

weixin_30737433的博客 133

Stones on the Table CodeForces - 266A

**#include&lt;iostream&gt; #define N 50 using namespace std; int main() { int n,i,take=0; cin&gt;&gt;n;//石头的数量,1~50 char str1[N]; for(i=0;i&lt;n;i++)//输入石头的颜色 cin&gt;&gt;str1[i]; fo...

flowingfish的博客 179

Codeforces——266A Stones on the Table

小声BB 大清早写的,困的要死 题干 time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take fr

真田伊廉的博客 273

CodeForces-266A-Stones on the Table

There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Sto...

weixin_43999137的博客 240

coderforces Stones on the Table

http://codeforces.com/problemset/problem/266/A import java.util.Scanner; public class Stones_on_the_Table { public static void main(String[] args) { Scanner scanner = new Scanner(System.

Lutte_的博客 321

Codeforces刷题之路——266A Stones on the Table

A. Stones on the Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n stones on the table in a

莫欺少年穷 742
上一篇: POJ 2245 Lotto (枚举)
下一篇: Codeforces Beta Round #91 (Div. 2) / 122A Lucky Division (数论)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值