A. Snow Footprints

A. Snow Footprints
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Input

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.

Output

Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.

Sample test(s)
input
9
..RRLL...
output
3 4
input
11
.RRRLLLLL..
output
7 5
Note

The first test sample is the one in the picture.

看别人敲出这题的时间感觉题目不是很难,但是俺还是花了一个小时,全因为细节问题,这题,只要仔细看题,把细节问题(例如一些特殊的测试数据:.R.和.L.这个看上去一样其实起始位置和终点位置是不一样的),下面我先解释下题目意思:这道题其实就按照在雪地上的脚印让你得出脚印的起始位置和终点位置,这道为什么不难,就是因为从雪地上的脚印我们可以得出多个解,而且题目说了如果有多个解可以给出任意一个解,所以我们就取最简单,我从最左边走到最右边或者从最右边走到最左边等等采取极端方法,说明下我们得出的测试结果可能和题目上给出不同,但只要合理能就能AC,好吧这题其实我也不废话,看我的代码你就能理解我说的话了。
下面是代码及其测试数据:
#include<iostream>
#include<string.h>
const int MAX=1500;
char s[MAX];
using namespace std;
int main()
{
int n,m,i,j,start,end,q,p,a,b;
cin>>n;
cin>>s;
m=strlen(s);
a=0;
b=0;
p=1;
q=1;
for(i=1;i<m;i++)
{
if(s[i]=='.')
continue;
if((s[i]=='R'||s[i]=='L')&&p)//P的意思是为了得到开始点,因为执行一次后P为0,以后这个语句就不会执行了
{
p=0;
start=i+1;
}
if((s[i-1]=='R'&&s[i]=='L')||(s[i-1]=='L'&&s[i]=='R')&&q)//同理q和P一样
{
end=i;
q=0;
}
if(s[i]=='R')
a+=1;
if(s[i]=='L')
b+=1;
}
if(a!=0&&b!=0)//如果a和b都不为0那么上个for循环里的start和end就是结果了,如果不是下面要分情况讨论而且起始点和终点要重新得出
{
cout<<start<<" "<<end<<endl;
}
if(a==0&&b!=0)
{
for(i=0;i<n;i++)
{
if(s[i]!='.')
{
end=i;
break;
}
}
for(i=n-1;i>=0;i--)
{
if(s[i]!='.')
{
start=i+1;
break;
}
}
cout<<start<<" "<<end<<endl;
}
if(b==0&&a!=0)
{
for(i=0;i<n;i++)
{
if(s[i]!='.')
{
start=i+1;
break;
}
}
for(i=n-1;i>=0;i--)
{
if(s[i]!='.')
{
end=i+1;
break;
}
}
cout<<start<<" "<<end+1<<endl;
}
if(a==0&&b==0)//这个为全是'.'的情况,所以随便输出一个结果,当然结果要比n小
{
cout<<2<<" "<<2<<endl;
}
return 0;
} //如果有问题,或有什么疑惑,可以在评论中提出,小子我看到一定尽力解答
测试数据:
Checker Log
ok ok
Test: # 2, time:  15 ms., memory:  0 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok ok
Test: # 3, time:  0 ms., memory:  0 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok ok
Test: # 4, time:  0 ms., memory:  0 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok ok

       
       
Test: # 8, time:  0 ms., memory:  0 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok ok
Test: # 9, time:  0 ms., memory:  0 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok ok
Test: # 10, time:  0 ms., memory:  0 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok ok



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值