cf 465 B. Fafa and the Gates

研发流程后端开发工具,提示功能开发效率 后端开发工具 立即下载
B. Fafa and the Gates
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.

The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.

Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).

Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.

Input

The first line of the input contains single integer n (1 ≤ n ≤ 105) — the number of moves in the walking sequence.

The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.

Output

On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.

Examples
Input
Copy
1
U
Output
0
Input
Copy
6
RURUUR
Output
1
Input
Copy
7
URRRUUU
Output
2
Note

The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.

The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.

Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).

Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.

Input

The first line of the input contains single integer n (1 ≤ n ≤ 105) — the number of moves in the walking sequence.

The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.

Output

On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.

Examples
Input
Copy
1
U
Output
0
Input
Copy
6
RURUUR
Output
1
Input
Copy
7
URRRUUU
Output
2
Note

The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef double    dl ;
#define INF 0x7f
const int maxn =1e5+5; 

#define f(i,l,r) for(int i=l;i<=r;++i)
#define g(i,l,r) for(int i=l;i>=r;--i)
 char str[maxn];
int main()
{
     
   // freopen("in","r",stdin);
    int n;
    cin>>n;
    f(i,1,n)
     cin>>str[i];
    int x=0,y=0,ans=0;

	f(i,1,n)
	{
		// cout<<x<<" "<<y<<endl;
		if(str[i]=='U')
		{
			if(y==x&&str[i-1]=='U')
				ans++;
			y++;
		}
		 if(str[i]=='R') 
		{
			if(y==x&&str[i-1]=='R')
				ans++;
			x++;
		}
		 
	}
    cout<<ans<<endl;

    return 0; 
}
未来的我一定会感谢现在正在成长的我






【UVM实战】第七章:UVM中的寄存器模型(1)寄存器模型简介 寄存器模型简介~ 阅读详情

相关推荐

手把手教你用Three.js+Vue打造3D机房可视化系统(附完整代码)

本文详细介绍了如何使用Three.js与Vue 3构建企业级3D机房可视化系统。从技术选型、项目架构设计到3D场景构建、设备建模与渲染策略,提供了完整的开发方案和实战代码。重点讲解了如何实现设备状态实时监控、交互操作与性能优化,帮助开发者快速掌握3D可视化开发的核心技术。

ttt77的博客 317

935B. Fafa and the Gates

Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one sil...

码农的一亩三分地 470

开源有限元dealii学习——step-1

#简介 dealii是一款开源的求解偏微分方程的有限元软件,它优点: 1.多种单元类型 2.可以自适应网格 3.文档和范例齐全 4.与其它库有良好的接口 5.使用c++编写 #安装 dealii可以在官网上或者github上下载源码,解压后进入源文件目录安装。 mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=/path/to/install...

weixin_42312251的博客 4385

cf935B

B. Fafa and the Gates time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Two neighboring kingdoms decided to b

Every Master was once a disaster or beginner. 356

Multisim 14.0元件库下载权威指南:官方与社区资源

详解Multisim元件库下载的官方途径与可靠社区资源,帮助用户快速获取Multisim 14.0所需元件模型,提升电路仿真效率。

weixin_32925455的博客 753

【深度解析TI InstaSPIN】无传感器FOC控制的核心方案

TI InstaSPIN通过“自动识别+通用观测器+开源工具链”的组合,解决了无传感器FOC控制开发难度大、周期长的核心痛点。其核心优势在于快速统一软件观测器的通用性与高精度,以及Fly Start闭环零速启动策略的高可靠性,可适配空调压缩机等家电电机的复杂运行需求。在空调外机双电机控制场景中,InstaSPIN与TI C2000系列MCU(F280013x/F28E12x)完美契合,借助MCU的高性能DSP内核与丰富外设,可实现双电机的精准同步控制,同时降低硬件成本与开发周期。

昔时扬尘处 326

Fafa and the Gates(模拟)

Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay on...

weixin_30466953的博客 203

【Claude】API Error 通用错误:错误码含义与标准排查流程 bug报错已解决

Claude API 各类错误码速查与标准排查流程。

博客 8245

fafa

spring mvc =struts

f627319885的博客 292

蓝桥杯 stm32 PWM 测量频率

参考 数据手册:比赛 的板子 上面有两个信号发生器,如下图。通过 扭动 可变电阻 (R40, R39), 来实现 PWM 频率的改变。PA15PB4。PA15,PB4分别使用TIM2_CH1TIM3_CH1来对频率进行捕获。

wuyiyu_的博客 2931

使用 MATLAB/Simulink + Simscape Electrical + Simulink Design Optimization,构建一个沙漠环境中光伏组件灰尘积累与效率下降仿真模型

本文通过,构建了沙漠环境中光伏组件灰尘积累与效率下降仿真模型✅ 建立了风速-沙尘-积尘速率的物理关系✅ 仿真了灰尘积累过程及其对Isc 和 Pmax的影响✅ 量化分析了不同清洁策略的经济性✅ 提出了优化设计与智能运维建议。

xiaoheshang_123的博客 123

cf 468 C. Convenient For Everybody

恶心........ 知道怎么做就是时间没算出来,你说尴不尴尬从国外友人哪里学到 时间打法 循环余 改变时间 看代码简单易懂版本C. Convenient For Everybodytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn dist...

PragIncor的博客 800

区块链技术与应用 【全国职业院校技能大赛国赛题目解析】Caliper从0到使用

技能大赛样题解析,caliper题目从0到使用

weixin_52865146的博客 2077

cf462 A Twisty Movement

标准动态规划dp [i][j][0] 从i 到 j 的有多少1结尾的非递增子序列 ( 21 或 1 )dp [i][j][1] 从i 到 j 的有多少2结尾的非递增子序列 只有2 处理一下 多少个1 多少个 2 ,就可以get  C. A Twisty MovementA dragon symbolizes wisdom, power and wealth. On Lunar Ne...

PragIncor的博客 706

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

cf 464 B. Hamster Farm

B. Hamster Farmtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima has a hamsters farm. Soon N hamsters will grow up on it and Dima will ...

PragIncor的博客 661

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

cf 464 D. Love Rescue

快速栈 虽然修改比较麻烦 但是 直接字符数组乱搞了 就是替换 D. Love Rescuetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValya and Tolya are an ideal pair, but they quarrel s...

PragIncor的博客 576

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

<cf> A. Cloning Toys

time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputImp likes his plush toy a lot. Recently, he found a machine that can clone plush toys. Imp ...

PragIncor的博客 571

cf 465C. Fifa and Fafa

C. Fifa and Fafatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFifa and Fafa are sharing a flat. Fifa loves video games and wants to download a ne...

PragIncor的博客 560

cf 462 E - Maximize!

 两个操作 处理和查询 分开做了首先他要处理的那个中间数值  搞搞就好了,还有注意两个事情 地方开大点 应为开成了 1e5 挂了好多次 E. Maximize!time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a mu...

PragIncor的博客 527

<cf>B. Magic Forest

time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputImp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-d...

PragIncor的博客 503

<cf>C. Cave Painting

注意:多读一下 题目:这是精巧的归纳一个观点 :  a%b =c ===&gt; c &lt;b  所以当 i== 1 c == 0      2    1    ....    .. 我只想说 这个题目太皮了  time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutpu...

PragIncor的博客 498

cf 466

A     Points on the line具体找间距k内的点多少个其余删除 就是直接暴力了#include &lt;bits/stdc++.h&gt; using namespace std; typedef long long ll ; typedef double dl ; #define INF 0x7f const int maxn =1e5+5; const int mod...

PragIncor的博客 491

cf 465 A. Fafa and his Company

A. Fafa and his Companytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFafa owns a company that works on huge projects. There are n employees in Fa...

PragIncor的博客 455

cf462 A Determined Cleanup

D. A Determined Cleanuptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn order to put away old things and welcome a fresh new year, a thor...

PragIncor的博客 446

cd A Colourful Prospect

卡案例10 了 ,枚举实在过不去了 #include&lt;iostream&gt; #include&lt;cmath&gt; using namespace std; typedef long long ll ; #define f(i,l,r) for(int i=l;i&lt;=r;i++) #define g(i,l,r) for(int i=l;i&gt;=r;i--) const i...

PragIncor的博客 412

cf462 A Compatible Pair

暴力直接找max A. A Compatible Pair     Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people...

PragIncor的博客 394
上一篇: cf 465 A. Fafa and his Company
下一篇: cf 465C. Fifa and Fafa
PragIncor
博客等级 码龄9年 1粉丝 59原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值