A. Snow Footprints
来源:互联网 发布:广州酒店推荐知乎 编辑:程序博客网 时间:2024/05/16 15:20
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one.
At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road.
You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
The first line of the input contains integer n (3 ≤ n ≤ 1000).
The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.
9..RRLL...
3 4
11.RRRLLLLL..
7 5
The first test sample is the one in the picture.
解题说明:此题是模拟题,首先找到第一个字母所在的位置,然后按照R L进行模拟走
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;char p[1001];int main(){int n,i,s,r,t;scanf("%d", &n);for (i = 0; i < n; ++i){scanf(" %c ", &p[i]);}s = 0;while (p[s] == '.'){s++;}r = s;while (p[r] != '.'){r++;}t = r;while (p[t - 1] == 'L'){t--;}if (p[t] != '.'){t--;}printf("%d %d\n", s + 1, t + 1);return 0;}
- 298A Snow Footprints
- A. Snow Footprints
- A. Snow Footprints
- codeforce 298 A Snow Footprints
- CodeForces 298A Snow Footprints
- Snow Footprints
- Codeforces-298a G Snow Footprints
- Codeforces 298A Snow Footprints 题解
- Codeforces Round #180 (Div. 2) A. Snow Footprints 【思维+模拟】
- 文章标题 CoderForces 298A: Snow Footprints(水)
- a timely snow promises a good harvest
- footprints 大全
- Snow
- Snow
- Codeforce 298 A snow Footprint 思维问题
- CodeForces 613A Peter and Snow Blowe
- codeforces 613A Peter and Snow Blower
- 70. A snow year, a rich year. 瑞雪兆丰年
- eclipse配置tomcat
- 证书之间的转换
- extjs struts1 传参乱码问题
- JavaScript交流贴
- VE中如何启用批次管理及与产品批次相关的单据
- A. Snow Footprints
- maven复制jar包到本地仓库
- DXUT实战2:HLSL(withoutEffect)+D3D9+DXUT(june_2010) .
- python06 字符串和文本
- MySQL 如何从其他主机连接数据库
- Greenplum receive close on connection: Success (cdbfilerepconnserver.c:334) 错误分析
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- PADS 元件编辑器中的几个名词概念
- GDB跳出函数的相关文章