CF 264A (inbound bidirectional Queue)

Source: Internet
Author: User

C. escape from Stonestime limit per test 2 secondsmemory limit per test 256 megabytesinput standard inputoutput standard outputSquirrel Liss lived in a forest peacefully, but unexpected trouble happens. stones fall from a mountain. initially Squirrel Liss occupies an interval [0, limit 1]. next, n stones will fall and Liss will escape from the stones. the stones are numbered from 1 to n in order. the ston Es always fall to the center of Liss interval. when Liss occupies the interval [k hour-week d, every k hour + week 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 rows-between d, between k]. if she escapes to the right, her new interval will be [k, 1_k + 1_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. www.2cto. comInputThe input consists of only one line. the only line contains the string s (1 bytes ≤ bytes | s | bytes ≤ limit 106 ). each character in s will be either "l" or "r ". outputOutput n lines-on the I-th line you shoshould print the I-th stone's number from the left. sampl E test (s) inputllrlroutput35421inputrrllloutput12543inputlrroutput24531notein the first example, the positions of stones 1, 2, 3, 4, 5 will be, respectively. so you shoshould print the sequence: 3, 5, 4, 2, 1. it cannot be simulated by double + division. It will be too precise !! (Long double does not work) In fact, As long as according to the nature, before and after the sequence can be added. Rely on, the virgins in life, Hack, is actually being Hack... (Subject ?) [Cpp] # include <cstdio> # include <iostream> # include <cstdlib> # include <cstring> # include <cmath> # include <functional> # include <algorithm> # include <cctype> using namespace std; # define MAXN (1000000 + 10) // pair <double, int> a [MAXN]; char s [MAXN]; int n, a [MAXN]; int main () {scanf ("% s", & s); n = strlen (s); int l = 1, r = n; for (int I = 0; I <n; I ++) {if (s [I] = 'l') a [r --] = I + 1; else a [l ++] = I + 1 ;} for (int I = 1; I <= n; I ++) cout <a [I] <endl ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.