Codeforces 264A. Escape from Stones

Squirrel Liss lived 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 swill 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.

最初用vector做的,一直超,后来换了数组发现还是超,才想到是cin,cout的问题,加了一句sync果然好多了

#include <cstdio>
#include <cctype>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long LL;

int total = 0;
int lv[1000005] = {0};
string s;
int main() {
  // freopen("test.in","r",stdin);
  ios::sync_with_stdio(false);
  cin >> s;
  int len = s.length();
  for (int i=0;i<len;i++){
    int now = i+1;
    if (s[i] == ‘l‘){
      total ++;
      lv[total] = now;
    }
    else {
      cout << now << endl;
    }
  }
  for (int i=total;i>=1;i--){
    cout << lv[i] << endl;
  }

  return 0;
}

时间: 2024-10-06 00:30:52

Codeforces 264A. Escape from Stones的相关文章

CodeForces 264A Escape from Stones dfs

题目链接:点击打开链接 题意:开始有一个区间[0,1] 每次操作在中间填i,然后选择坐半段或者右半段(给出选择的方案,然后从左到右输出填写的i) (i=1 2 3···) #include <cstdio> char s[1000005]; void dfs(int x){ if(s[x] == 0)return ; if(s[x] == 'l') { dfs(x+1); printf("%d\n", x+1); } else { printf("%d\n&quo

Codeforces Round #162 (Div. 1) A. Escape from Stones

A. Escape from Stones time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squ

CodeForces 148B Escape

Escape Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 148B Description The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp mil

Codeforces 932F - Escape Through Leaf

Problem Link: http://codeforces.com/contest/932/problem/F Problem Statement: F. Escape Through Leaf time limit per test: 3 seconds memory limit per test:256 megabytes input: standard input output: standard output You are given a tree with n nodes (nu

Codeforces Round #162 (Div. 2) A~D 题解

A. Colorful Stones (Simplified Edition) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You a

动态规划,就是这样! CodeForces 433B - Kuriyama Mirai&#39;s Stones

Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: She wi

Codeforces Round #248 (Div. 2) B - Kuriyama Mirai&#39;s Stones

题意 给出一个n个数的序列.下面有m个指令 1指令:原序列从l到r的和 2指令:排序过的序列从l到r的和 思路 线段树可做-.直接扫一遍记录sum数组也可以 代码 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; #define ll long long const int maxn = 100010; int n; int s[maxn]; int ss[max

CodeForces Gym 101047E Escape from Ayutthaya BFS

Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 101047E Description standard input/output Ayutthaya was one of the first kingdoms in Thailand, spanning since its foundation in 1350 to its collaps

Magic Stones CodeForces - 1110E (思维+差分)

E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is equal to cici. Sometimes G