CodeForces

来源:互联网 发布:博雅软件怎么用 编辑:程序博客网 时间:2024/06/05 00:08

奇妙的一个题   最后一轮的A点击打开链接


我把题目看错了!,请zzh仔细阅读红色字体部分!!!

There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 ton from left to right. If one moves from thei-th block to the (i + 1)-th block, he will leave a right footprint on thei-th block. Similarly,if one moves from thei-th block to the(i - 1)-th block, he will leave a left footprint on thei-th block. If there already is a footprint on thei-th block, the new footprint will cover the old one.

At the beginning, there were no footprints. Then polar bear Alice starts from thes-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 ofs, 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 ofn 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 andt. If there are several possible solutions you can print any of them.

Example
Input
9..RRLL...
Output
3 4
Input
11.RRRLLLLL..
Output
7 5
Note

The first test sample is the one in the picture.


怕是个傻子!!!  他是走过一个路 走过去才会留下脚印,也就是说他当前的位置是不会有脚印的



然后经过一番研究发现,奇妙的是,他不会存在LR的情况,也就是说,只要他走,就只有三种情况,

1  全是L

2 全是R

3 先R再L  (并且R L 一定是连续出现的不会有RLR或者LR 或者LRL  )   


关于起点,三种情况是一样的就是说:起点全部都是第一个出现脚印的点

关于终点: 1,在起点的左边   

                  2,在最后一个R的右边

                  3,在第一个L出现的位置的左边


就是这样,,,,好有规律的一个题目

wa了n次总算是得出一个清晰地结论不错不错,虽然是个水题


上代码:

#include <iostream>#include<cstring>using namespace std;const int maxn=1000+5;char s[maxn];int main(){    int n;    cin>>n;     memset(s,0,sizeof(s));    for(int i=1;i<=n;i++)    cin>>s[i];    int be=0,en=0;    int flag=0;    int r=0;    for(int i=1;i<=n;i++)    {       if(s[i-1]=='R'&&s[i]=='L')       {           flag=1;           en=i-1;       }       if((s[i-1]=='.'&&s[i]=='R')||(s[i-1]=='.'&&s[i]=='L'))        be=i;       if(s[i]=='R')          r=1;       if(!flag&&(s[i]=='R'&&s[i+1]=='.'))          en=i+1;    }     if(s[1]=='R'||s[1]=='L')        be=1;     if(!flag&&s[n]=='R')        en=n+1;     if(!r)        en=be-1;    cout << be<<" "<<en << endl;    return 0;}

或者这样来

#include <iostream>using namespace std;const int maxn=1000+5;char s[maxn];int main(){    int n;    while(cin>>n)    {        for(int i=1;i<=n;i++)    cin>>s[i];    int be=0,en=0;    int flag=0;    int x=0,y=0;    for(int i=1;i<=n;i++)    {        if(!flag&&(s[i]=='L'||s[i]=='R'))        {            be=i;            flag=1;        }        if(s[i]=='L')          y=1;        if(s[i]=='R')            x++;    }    if(y)    cout << be<<" "<<be+x-1<< endl;    else        cout<<be<<" "<<be+x<<endl;    }    return 0;}



原创粉丝点击