codeforce 298 A Snow Footprints


查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记录吧!

There is a straight snowy road, divided intonblocks. The blocks are numbered from 1 tonfrom 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, tby looking at the footprints.

Input

The first line of the input contains integern(3 ≤ n ≤ 1000).

The second line contains the description of the road — the string that consists ofncharacters. 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 ofsandt. If there are several possible solutions you can print any of them.

input
9
..RRLL...

output
3 4

input
每日一道理
站在历史的海岸漫溯那一道道历史沟渠:楚大夫沉吟泽畔,九死不悔;魏武帝扬鞭东指,壮心不已;陶渊明悠然南山,饮酒采菊……他们选择了永恒,纵然谄媚诬蔑视听,也不随其流扬其波,这是执著的选择;纵然马革裹尸,魂归狼烟,也要仰天长笑,这是豪壮的选择;纵然一身清苦,终日难饱,也愿怡然自乐,躬耕陇亩,这是高雅的选择。在一番选择中,帝王将相成其盖世伟业,贤士迁客成其千古文章。
11
.RRRLLLLL..

output
7 5

Note

The first test sample is the one in the picture.

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char input[1010];
int r1=0,r2=0,l1=0,l2=0;
void getr()
{
int i;
for(i=0;i<strlen(input);i++)
{
if(input[i]=='R')
{
r1=i;
break;
}
}
if(i==strlen(input))
{
r1=-1;
r2=-1;
return;
}
else
{
for(i=strlen(input)-1;i>=0;i--)
{
if(input[i]=='R')
{
r2=i;
break;
}
}
}
}
void getl()
{
int i;
for(i=strlen(input)-1;i>=0;i--)
{
if(input[i]=='L')
{
l2=i;
break;
}
}
if(i<0)
{
l1=-1;
l2=-1;
return;
}
else
{
for(i=0;i<strlen(input);i++)
{
if(input[i]=='L')
{
l1=i;
break;
}
}
}
}
void solve()
{
if(r1==-1)
{
printf("%d %d\n",l2+1,l1);
}
else if(l2==-1)
{
printf("%d %d\n",r1+1,r2+2);
}
else
{
printf("%d %d\n",r1+1,r2+1);
}
}
int main(int argc, char *argv[])
{
//freopen("data.in","r",stdin);
int len;
while(scanf("%d",&len)!=EOF)
{
scanf("%s",input);
getr();
getl();
solve();
}
return 0;
}

文章结束给大家分享下程序员的一些笑话语录: 腾讯的动作好快,2010年3月5日19时28分58秒,QQ同时在线人数1亿!刚刚看到编辑发布的文章,相差才2分钟,然后连专题页面都做出来了,他们早就预料到了吧?(其实,每人赠送10Q币,轻轻松松上两亿!)

优质内容筛选与推荐>>
1、Emacs编辑命令速查
2、如何利用系统函数操作文件夹及文件
3、JavaScript 弹出窗口总结
4、python中的排序函数
5、《JavaScript权威指南》读书笔记(2)-词法结构


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn