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 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 equationx = 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.
Description

Input
Output
1
U
0
6
RURUUR
1
7
URRRUUU
2 解题思路:分别记录向上和向右移动的步数,如果移动到了对角线位置,并且下一次移动将要出对角线(城门和墙)到另外的国家,则需要支付一次银币。
#include<stdio.h>
int main()
{
int n,i,j,x,y,count;
char s[];
scanf("%d",&n);
getchar();
gets(s);
x=,y=;
count=;
for(i=;i<n;i++)
{
if(s[i]=='U')
{
y++;
}
else if(s[i]=='R')
{
x++;
}
if(x==y&&s[i]==s[i+])
{
count++;
}
}
printf("%d\n",count);
return ;
}
Fafa and the Gates(模拟)的更多相关文章
- B. Fafa and the Gates
http://codeforces.com/problemset/problem/935/B Two neighboring kingdoms decided to build a wall betw ...
- CF935B Fafa and the Gates 题解
Content 一个动点 \(F\) 一开始在平面直角坐标系上原点的位置,随后它会移动 \(n\) 次,每次只能向上走或者向右走 \(1\) 个单位,求经过直线 \(y=x\) 的次数. 数据范围:\ ...
- [NOIP2018模拟赛10.22]咕咕报告
闲扯 这是篇咕咕了的博客 考场上码完暴力后不知道干什么,然后忽然发现这个T1好像有点像一道雅礼集训时讲过的CF题目 Rest In Shades ,当时那道题还想了挺久不过思路比较妙,于是我就也\(y ...
- [NOIP2018模拟赛10.16]手残报告
[NOIP2018模拟赛10.16]手残报告 闲扯 炉石乱斗模式美滋滋啊,又颓到好晚... 上来T2先敲了树剖,看T1发现是个思博DP,然后没过大样例,写个暴力发现还是没过大样例!?才发现理解错题意了 ...
- [NOIP10.6模拟赛]2.equation题解--DFS序+线段树
题目链接: 咕 闲扯: 终于在集训中敲出正解(虽然与正解不完全相同),开心QAQ 首先比较巧,这题是\(Ebola\)出的一场模拟赛的一道题的树上强化版,当时还口胡出了那题的题解 然而考场上只得了86 ...
- App开发:模拟服务器数据接口 - MockApi
为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
- Python 爬虫模拟登陆知乎
在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...
- HTML 事件(四) 模拟事件操作
本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4. ...
随机推荐
- C++ Primer 第8章作业
练习8.1 编写函数,接受一个istream&参数,返回值类型也是istream&. 此函数须从给定流中读取数据,直至遇到文件结束标识时停止.它将读取的数据打印在标准输出上.完成这些操 ...
- ThinkPHP5.0框架事务处理操作简单示例
本文介绍ThinkPHP5.0框架事务处理操作,结合实例形式分析了ThinkPHP5针对删除操作的事务处理相关操作技巧,可以加深对ThinkPHP源码的理解,需要的朋友可以参考下 事务的调用在mysq ...
- git 项目常用
本地分支推送到远程分支: (1),git init,git add . (2),git commit -m "首次提交" (3),git remote add origin '远程 ...
- react基本demo详解
一.react的优势 1.React速度很快:它并不直接对DOM进行操作,引入了一个叫做虚拟DOM的概念,安插在javascript逻辑和实际的DOM之间,性能好. 2.跨浏览器兼容:虚拟DOM帮助我 ...
- nginx php-fpm 高并发优化
PHP-php-fpm配置优化 前言: 1.少安装PHP模块, 费内存 2.调高linux内核打开文件数量,可以使用这些命令(必须是root帐号)(我是修改/etc/rc.local,加入ulimit ...
- flume搭建新手测试环境
硬件环境: 腾讯云,两台服务器8G 双核 软件环境: flume1.8.jdk1.8,centos6 第一次搭建也是各种找文件,只知道flume是日志抓取服务,也听说了非常稳定强大的服务,正好公司需要 ...
- WIN10远程连接winserver2012 r2,连接失败
背景:2012开启远程的时候,默认是勾选“仅允许运行使用网络级别身份验证的远程桌面的计算机连接”,这个选项据说比较安全,但是用win10远程的时候就报错,函数不受支持,最后通过修改win10的配置得以 ...
- STM32_1 搭建工程框架
搭建系统框架 -- 创建系统文件夹 -- 拷贝stm32库文件 -- 将文件添加至工程 -- 配置工程环境 1. 创建工程文件夹 找一个工程目录,我就在 stm32/Code 下创建一个模板工程Tem ...
- Emgucv安装及使用
Emgucv安装 最近有个客户联系我,希望我能够为他们做一个识别瓷砖花纹的软件.应用场景是这样的:现场会有一个摄像头去拍摄流水线上运输的瓷砖,如果检测这块瓷砖的花纹不符合要求,则需要给PLC或输出板卡 ...
- hdu 2031 进制转换(栈思想的使用)
进制转换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...