题目:

Squirrel Liss liv

Escape from Stonesed in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from
the stones. The stones are numbered from 1 to n in order.

The stones always fall to the center of Liss's interval. When Liss occupies the interval [k - d, k + d] and a stone falls to k, she will escape to the left or to the right. If she escapes to the left, her new interval will be [k - d, k]. If she escapes to the
right, her new interval will be [k, k + d].

You are given a string s of length n. If the i-th character of s is "l" or "r", when the i-th stone falls Liss will escape to the left or to the right, respectively. Find the sequence of stones' numbers from left to right after all the n stones falls.

Input

The input consists of only one line. The only line contains the string s (1 ≤ |s| ≤ 106). Each character in s will be either "l" or "r".

Output

Output n lines — on the i-th line you should print the i-th stone's number from the left.

Example

Input

llrlr

Output

3

5

4

2

1

Input

rrlll

Output

1

2

5

4

3

Input

lrlrr

Output

2

4

5

3

1

解题心得:

1、刚开始看到这个题的时候挺蒙蔽的,第一想法就是使用暴力,但是毫无疑问的是暴力肯定会将精度丢失,即使骗数据过了也容易被Hack。其实这个题有很多的解法

2、先说思路,题意上面说的很明白,当向左的时候最左方的一个是第一个r的前一个,最左方的r的是第一个r出现的时候,可以画一个图了解一下。

3、做法很多,了解了思路之后很简单,直接贴代码:

DFS:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
char a[maxn];
int n;
void dfs(int step)
{
if(step == n)
return;
if(a[step] == 'l')
{
dfs(step+1);
printf("%d ",step+1);
}
if(a[step] == 'r')
{
printf("%d ",step+1);
dfs(step+1);
}
}
int main()
{
while(scanf("%s",a)!=EOF)
{
n = strlen(a);
dfs(0);
}
}


栈:
其实和dfs差不多只不过看起来没那么迷糊!
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
char a[maxn];
int main()
{
scanf("%s",a);
int len = strlen(a);
stack <int> s;
for(int i=0; i<len; i++)
{
if(a[i] == 'l')
s.push(i+1);
else
printf("%d ",i+1);
}
while(!s.empty())
{
printf("%d ",s.top());
s.pop();
}
return 0;
}


双向队列:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
int k[maxn];
char s[maxn];
int main()
{
scanf("%s",s);
{
int len = strlen(s);
int start = 0,End = len - 1;
for(int i=0 ;i<len ;i++)
{
if(s[i] == 'l')
{
k[start] = i+1;
start++;
}
if(s[i] == 'r')
{
k[End] = i+1;
End--;
}
}
for(int i=len-1;i>=0;i--)
printf("%d ",k[i]);
}
}



DFS、栈、双向队列:CF264A- Escape from Stones的更多相关文章

  1. 剑指offer:按之字形打印二叉树(栈|双向队列+中序遍历)

    1. 题目描述 /** 请实现一个函数按照之字形打印二叉树, 即第一行按照从左到右的顺序打印, 第二层按照从右至左的顺序打印, 第三行按照从左到右的顺序打印, 其他行以此类推. */ 2. 双向队列 ...

  2. 剑指offer:对称的二叉树(镜像,递归,非递归DFS栈+BFS队列)

    1. 题目描述 /** 请实现一个函数,用来判断一颗二叉树是不是对称的. 注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的 */ 2. 递归 思路: /** 1.只要pRoot.left和 ...

  3. python 模块一(random,counter,defaultdict,time,wraps,reduce) 栈 队列 双向队列

    ####################总结####################### 模块:你写的py文件 引用其他模块 1.import 模块 2.from 模块 import 功能,类,变量 ...

  4. 算法进阶面试题02——BFPRT算法、找出最大/小的K个数、双向队列、生成窗口最大值数组、最大值减最小值小于或等于num的子数组数量、介绍单调栈结构(找出临近的最大数)

    第二课主要介绍第一课余下的BFPRT算法和第二课部分内容 1.BFPRT算法详解与应用 找到第K小或者第K大的数. 普通做法:先通过堆排序然后取,是n*logn的代价. // O(N*logK) pu ...

  5. Python 栈和队列,双向队列

    # 栈 # 特点: 先进后出 class StackFullException(Exception): pass class StackEmptyException(Exception): pass ...

  6. python基础知识4——collection类——计数器,有序字典,默认字典,可命名元组,双向队列

    1.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. ps:具备字典的所有功能 + 自己的功能  Counter 我们从中挑选一些相对常用的方法来举例: 在上面的例子 ...

  7. YTU 3006: 迷宫问题(栈与队列)

    3006: 迷宫问题(栈与队列) 时间限制: 1 Sec  内存限制: 128 MB 提交: 3  解决: 1 题目描述 编写一个求解迷宫问题的程序,要求输出迷宫的所有路径,并求最短路径长度及最短路径 ...

  8. 线性表 及Java实现 顺序表、链表、栈、队列

    数据结构与算法是程序设计的两大基础,大型的IT企业面试时也会出数据结构和算法的题目, 它可以说明你是否有良好的逻辑思维,如果你具备良好的逻辑思维,即使技术存在某些缺陷,面试公司也会认为你很有培养价值, ...

  9. PHP — 用PHP实现一个双向队列

    1.简介 deque,全名double-ended queue,是一种具有队列和栈的性质的数据结构.双端队列中的元素可以从两端弹出,其限定插入和删除操作在表的两端进行.双向队列(双端队列)就像是一个队 ...

随机推荐

  1. X64下IIS调用32位的dll

    WebAPI项目中遇到了需要调用32位C++的dll的情况,调试的时候能正常调用,但是发布了之后部署在IIS中出现了BadFormatImage异常, 解决方法是在IIS中相应应用程序池=>高级 ...

  2. Android图表库XCL-Charts

    首先,这个是国人开发的,支持下必须顶!github项目地址:点击打开,由于项目的基本功能已经实现,所以项目作者也说以后基本不会在有更新了. 项目简介: Android图表库(XCL-Charts is ...

  3. java中的递归思想及应用

    递归就是自己调自己,最需要注意的就是结束条件,否则可能就是死循环,导致内存溢出 public T a(Object x,Object y) { if(条件true) { a(x1,y1); } els ...

  4. h5新增属性本地存储

    ---恢复内容开始--- 存储的两种类型: localStorage 和 sessionStorage localstorage:没有时间限制的数据存储 sessionStorage  针对一个ses ...

  5. filter 拦截ajax请求

    1.filterpublic class SessonFilter implements Filter { private static Logger log = LoggerFactory.getL ...

  6. (转载)C#线程优先级详解

    计算机中经常会有多个任务同时运行,其中总有一些看起来更紧急,更需要优先完成.比如我们现在有两个任务,一个任务是下载一部电影,另一个任务是检测用户的输入.显然及时响应用户操作应具有更高的优先级,因为我们 ...

  7. zabbix中监控项报错

    报错信息: zabbix报错(Not all processes could be identified, non-owned process info will not be shown, you ...

  8. 使用Loadrunner监控Windows资源

    为了区分把装有loadrunner的机器称作A,被监控资源的服务器(windows)称作B 1.确保B机器Administrator账户是可使用状态:右键计算机→ 管理→ 本地用户和组→ 用户,其中A ...

  9. nginx 升级为最新版 nginx -1.12.0

    标签:nginx 公司目前使用的nginx版本比较低(nginx-1.0.12),请网络安全公司做了一下“远程安全评估”,发现有下列漏洞: nginx URI处理安全限制绕过漏洞(CVE-2013-4 ...

  10. webpack前端构建工具学习总结(二)之loader的使用

    Webpack 本身只能处理 JavaScript 模块,如果要处理其他类型的文件,就需要使用 loader 进行转换. Loader 可以理解为是模块和资源的转换器,它本身是一个函数,接受源文件作为 ...