codeforces 935 B. Fafa and the Gates

[ADS]单端电感和差分电感的感值和Q值计算公式 单端电感和差分电感的感值和Q值计算公式 阅读详情

Description

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
1
U
Output
0

Input
6
RURUUR
Output
1

Input
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.

figure for third sample


题意:从(0,0)出发,每次向右或向上移动一格,问之后穿过x=y的次数(在(0,0)不算)
思路:在x=y上的时刻,前后两次运动的方向如果相同就一定穿过了这条直线(导数的思想),而不同则没穿过。

#include <stdio.h>

int n;

int main() {
    char last, op;
    scanf("%d", &n);
    int x = 0, y = 0, ans = 0;

    scanf("%c", &op);

    //跳过回车的输入以及第一次运动的判断
    while (scanf("%c", &op)==1)
    {
        if (op == 'U') {
            ++y; break;
        }
        else if (op == 'R') {
            ++x; break;
        }
    }

    last = op;
    //从第二次运动开始记录穿过的次数
    for (int i = 1; i < n; ++i) {
        scanf("%c", &op);

        if (x == y&&last == op)
            ++ans;
        //更新位置
        if (op == 'U') 
            ++y;
        else if (op == 'R') 
            ++x;

        //更新last
        last = op;
    }
        printf("%d", ans);


}
如何使用tinyalas接口从usb录音的同时从扬声器播放 3、 以上步骤确认完后,就可以修改tinyhostless.c程序,tinyhostless的本质就是边pcm_read(),边pcm_write();但原本tinyhostless只支持对同一声卡进行操作,所有需要修改其代码,改成录音和播放可支持不同声卡,如果是模拟声卡,有回环测试,可以实现边录边播放,但涉及USB声卡时,就没有现场的类似功能,有时候客户因为硬件特殊性,会有从USB录音的同时从扬声器播放出来的需求,本文简要描述如何使用tinyalsa接口实现该需求; 阅读详情

相关推荐

深入解析V4L2框架与高通KMD在Camera驱动中的协同设计

本文深入解析了V4L2框架与高通KMD在Camera驱动中的协同设计。V4L2作为Linux内核标准视频驱动框架,提供了统一的设备抽象与数据流管理;而高通KMD则在其基础上,通过引入CRM等核心模块,构建了一套针对移动平台复杂相机系统的高效内核态驱动架构,实现了硬件配置与执行的解耦与智能调度。

qq_27496129的博客 1144

【CodeForces】【模拟】935 B Fafa and the Gates

【题目】http://codeforces.com/problemset/problem/935/B 【题意】在第一象限上有两个国家,分别在x=y上方和下方。在x=y上有城门,穿过城门要交钱。现在给出xx在地图上走的过程,问他交了多少钱。 【思路】模拟。记录他当前在那个国家,每当走到边界线上,下一次的操作要走到另一边的话,ans++; 【代码】 #include&lt;bits/stdc...

swqeaaa的博客 234

潜流式人工湿地计算_复合人工湿地净化水产养殖污水技术

技术概论1. 定义与分类人工湿地是指用人工筑成水池或沟槽,底面铺设防渗漏隔水层,充填一定深度的基质层,种植水生植物,利用基质、植物、微生物的物理、化学、生物三重协同作用使污水得到净化的系统。当池塘养殖污水进入人工湿地时,其污染物被床体吸附、过滤、分解而达到水质净化作用。按照水体流动方式,人工湿地分为表面流人工湿地、水平潜流人工湿地、垂直潜流人工湿地以及由前面几种湿地混合搭配的组合式人工湿...

weixin_42365490的博客 4244

Codeforces 935B 暴力

传送门:题目 题意: 一个人只在平面第一象限运动,他只会往上走和往右走,每次直走一格距离,问穿过y=x这条线的次数,注意是穿过,如果只碰了一下,然后又回来则不算, 题解: 题目很简单,代码也很短,比赛的时候写复杂了,这里记录一下较为简单的解法: 比赛的时候想的是for循环模拟走,x和y数组记录足迹,如果碰到y=x,标记一下,然后继续走,如果由标记,判断本次的点和上上次的中点,是不是在y=...

shadandeajian的博客 314

将点云坐标转换成世界坐标的demo

将点云坐标转换成世界坐标的demo

howard789的博客 2206

使用TinyProxy搭建代理服务器

背景 办公电脑所在网络无法连接外网,机房服务器可以连接外网,通过服务器代理上网; 一、CentOS下TinyProxy安装–搭建代理服务器 TinyProxy是个轻量级简单的HTTP/HTTPS代理程序,GitHub和官网,安装方式这里主要介绍两种 CentOS下yum安装,参考:TinyProxy安装 Docker安装 先安装docker环境yum install docker -y 二、Win10下使用 ...

椰汁菠萝 1万+

Codeforces Round 935 (Div. 3)(A,B,C,D,E,F)

Codeforces Round 935 (Div. 3)(A,B,C,D,E,F)

qq_45809243的博客 1846

STM32F429移植LVGL9.3.0:从源码配置到双缓冲优化实战

本文详细介绍了如何在STM32F429平台上移植LVGL 9.3.0图形库,涵盖从源码准备、工程配置、显示驱动适配到双缓冲优化等关键步骤。重点解析了利用STM32F429的硬件特性实现高效内存管理和流畅显示性能的实战技巧,为嵌入式GUI开发提供完整解决方案。

q6r7s8t9的博客 1125

3.21总结​.Codeforces 第 935 轮(第 3 组)(A~D)题解​

这道题主要考察对题目的理解和前缀和的知识(比赛的时候没有前缀超时了),去网上看了一些题解对题目的了解更加通透了,其实就是通过一个前缀和计算不同位置的和,然后表示出0和1的分布情况,最后做判断,每一边满意度是否过半。这到题是一道思维题,理解题目意思就会觉得很简单首先内向的人肯定是一个人一个帐篷,我们只要关心外向的人就可以了,我们只要分外向的人可不可以被3整除,分成两种情况再讨论就可以了.(直接给原文了,我电脑的翻译就是一坨.......)

sin1810335764的博客 369

属性基加密(Attribute-based Encryption, ABE)

KP-ABE中,用户的密钥定义了访问策略,密文的属性与策略进行匹配。CP-ABE中,密文定义了访问策略,用户的属性与策略进行匹配。

2201_75392924的博客 1830

[Dify实战] OA 公文排版助手:自动格式化、编号、生成摘要-带配套资源

摘要: Dify 公文排版助手通过自动化解决公文处理中的格式混乱、编号错漏等问题。支持标题层级自动编号、摘要生成、要素补全等功能,输出标准化Markdown格式。核心流程包括输入原文、智能识别、自动排版与要素输出,适用于通知、纪要等场景。实施需统一模板规则,规范输入格式,并通过试跑优化纠错率与处理效率。关键价值在于减少人工返工,提升排版一致性,未来可对接OA系统实现全流程自动化。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 470

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

Unreal5从入门到精通之初学者碰到解决不了的问题怎么办?

在学习Unreal的过程中,你曾陷入困境了吗?对于我来说,这种情况发生得比我愿意承认的要多得多。幸运的是,除了一般地在网上搜索之外,还有很多地方可以获得虚幻引擎的帮助。

TxNet 977

codeforces 935B. Fafa and the Gates(简单)

题目链接 http://codeforces.com/problemset/problem/935/B解题思路:每次判断当前状态下的小三角形直角边的长度关系。#include&lt;iostream&gt; using namespace std; char s[100005]; int main() { int n; while(cin&gt;&gt;n) { ...

HJ 461

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Fafa and the Gates(CodeForces 935B)

Description 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 t...

Baiyi_destroyer的博客 343

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Codeforces 935B Fafa and the Gates

题意:    问小A能穿过几次x=y的直线AC:    #include&lt;bits/stdc++.h&gt; using namespace std; #define mp make_pair #define LL long long #define N 100005 #define inf 0x3f3f3f3f char str[N]; int main() { int n; ...

努力打工 258

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Codeforces-935C: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...

Mitsuha_的博客 984

Codeforces Round #465 (Div. 2) C. Fifa and Fafa[几何]

C. Fifa and Fafa time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Fifa and Fafa are sharing a flat. Fifa love

Haipai1998的博客 334

Codeforces Round #468 B. World Cup

B. World CupThe last stage of Football World Cup is played using the play-off system.There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the r...

s540239976的博客 568

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

Codeforces Round #465 (Div. 2) B. Fafa and the Gates

B. Fafa and the GatesTwo 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, ...

s540239976的博客 461

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

CodeForces 935D

题目大意:    有两个字符串 (x,y)由m中字符的编号组成(1,m)被遮挡住的字符用0表示为x串比y串大的概率 (编号大,从第一位开始假设两个位置相同,比较下一位)分析:    需要用到逆元,情况有:我们要的答案就是p(0)可以递推/递归计算代码:    #include&lt;bits/stdc++.h&gt; using namespace std; #define mp make_pai...

努力打工 396

[ 线段树 树状数组 ] Codeforces935F Fafa and Array

先考虑询问。 对于边界的点直接更新答案。 对于不在边界上的点: 若 ai−1≤aiai−1≤aia_{i-1}\le a_i 且 ai+1≤aiai+1≤aia_{i+1}\le a_i ,增大 aiaia_i 时答案的增加量为 2x2x2x 。 若 aiaia_i 在 ai−1ai−1a_{i-1} 和 ai+1ai+1a_{i+1} 之间,设 t=max(ai−1,ai+1)−ait=...

gjghfd 449

[CodeForces939F]Cutlet

题意: 有2×n2×n2\times n的时间去煎一块两面的肉 给你kkk个不相交时间区间[li,ri][li,ri][l_i,r_i] 你可以在这些区间的时间内任意次翻转这块肉 问是否存在合法的方案使得两面恰好都只煎了nnn分钟 求最少翻转次数 n≤105,k≤100n≤105,k≤100n\le10^5,k\le100 考虑暴力DP,fi,jDP,fi,jDP,f_{i,...

BeNoble_的博客 575

codeforces 935-C.Fifa and Fafa(几何)

http://codeforces.com/problemset/problem/935/C 题目大意: 给出一个圆的圆心和半径,另外再给出一个点,问在这个圆内求一个最大的圆保证这个点不在这个圆内(可以在圆上),求圆的圆心和半径。 解题思路: 利用相似三角形,先判断圆心和点的距离大于半径和两点重合的情况,再结合相似求出圆心即可。 #include&lt;iostream&gt; #inc...

HJ 415
上一篇: codeforces 935 A. Fafa and his Company
下一篇: codeforces 935 C. Fifa and Fafa
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值