I - 一次元リバーシ / 1D Reversi(水题)
Problem Statement
Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1≦i≦|S|) stone from the left. If the i-th character in S is B, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is W, it means that the color of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
Constraints
- 1≦|S|≦105
- Each character in S is BorW.
Input
The input is given from Standard Input in the following format:
S
Output
Print the minimum number of new stones that Jiro needs to place for his purpose.
Sample Input 1
BBBWW
Sample Output 1
1
By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.
In either way, Jiro's purpose can be achieved by placing one stone.
Sample Input 2
WWWWWW
Sample Output 2
0
If all stones are already of the same color, no new stone is necessary.
Sample Input 3
WBWBWBWBWB
Sample Output 3
9
题解:只需统计字符串中不同区间的个数即可
想想自己当时想那么麻烦,真的有种想呵呵的感觉,继续加油吧少年!
AC代码
#include<stdio.h>
#include<string.h> int main()
{
char s[];
scanf("%s", s);
int len = strlen(s);
int ans = ;
for(int i = ; i < len; i++)
{
if(s[i] != s[i-])
ans++;
}
printf("%d\n", ans); return ;
}
I - 一次元リバーシ / 1D Reversi(水题)的更多相关文章
- HDOJ 2317. Nasty Hacks 模拟水题
		Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ... 
- ACM :漫漫上学路 -DP -水题
		CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ... 
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
		1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ... 
- [poj2247] Humble Numbers (DP水题)
		DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ... 
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
		1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ... 
- BZOJ 1303 CQOI2009 中位数图 水题
		1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ... 
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
		B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ... 
- ACM水题
		ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ... 
- CF451C Predict Outcome of the Game 水题
		Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ... 
随机推荐
- SQL 由人员汇总到部门树递归合计总数函数
			1.由人员计算出总数,在部门树(tree)按结构汇总(主父绑定) CREATE function [dbo].[GetEmpDepNum] ( @ID int ) RETURNS @Tree Tabl ... 
- django的settings.py设置static
			DEBUG = True ################ STATICFILES ################ # A list of locations of additional stati ... 
- 实验吧CTF题库-密码学(部分)
			这里没有key: 打开链接,有一个弹窗 然后就是一个空白网页,右键查看源代码 这里有一串js密文,解密一下,https://www.dheart.net/decode/index.php 得到flag ... 
- ORACLE——日期时间格式化参数详解 之二
			2.8 DD 指定日期在当月中第几天(范围:1-31) SQL> select to_char(sysdate,'DD YYYY-MM-DD PM hh24:mi:ss ') from dual ... 
- 1.《Spring学习笔记-MVC》系列文章,讲解返回json数据的文章共有3篇,分别为:
			转自:https://www.cnblogs.com/ssslinppp/p/4528892.html [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://w ... 
- Delphi IOS (二)
			1.Mac 中 simulator模拟器Home快捷键:command(Win键盘,Ctrl与Alt之间的键)+shift+h来代替,也可以点击菜单>HardWare>Home 2.iPh ... 
- lucene 5.2.0学习笔记
			package com.bc.cas.manager; import com.bc.cas.dao.BookDao; import com.bc.cas.model.entity.Book; impo ... 
- dos 下bat 常用符号
			1.@一般在它之后紧跟一条命令或一条语句,则此命令或语句本身在执行的时候不会显示在屏幕上.请把下面的代码保存为test.cmd文件,然后运行,比较一下两条echo语句在屏幕上的输出差异: ech ... 
- PHP自定义函数获取汉字首字母的方法
			使用场景:城市列表等根据首字母排序的场景 function getFirstCharter($str) { if (empty($str)) { return ''; } $fchar = ord($ ... 
- Contset Hunter 1102 高精度求卡特兰数
			用递推的方式写的写挂了,而如果用组合数又不会高精度除法,偶然看到了别人的只用高精度乘低精度求组合数的方法,记录一下 #include<bits/stdc++.h> using namesp ... 
