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 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.

1()题目大意 ,

就是说 一个 一个人 站在一个 0 - 1的线段上, 最开始站在中点处,然后会有炸弹不断的向下落到他当前的位置,他会向左/右跑每次移动的距离缩小到上一次的1/2,(第一次1/4,第二次1/8........)

输出 ,在这条线段上的每个点处(被炸弹轰过的地方)的顺序是什么 。。。具体看例子把..只能说到这个地步了

(2)思路,这道题我想的是只考虑当前点,那么如果向右,那么这个点就是当前的最后一点,因为每次移动的距离缩小一半,也就是说她之后无论怎么向左移动,都无法到达当前点,同理,向左移动的话是一样的

 1 #include <algorithm>
 2 #include <stack>
 3 #include <istream>
 4 #include <stdio.h>
 5 #include <map>
 6 #include <math.h>
 7 #include <vector>
 8 #include <iostream>
 9 #include <queue>
10 #include <string.h>
11 #include <set>
12 #include <cstdio>
13 #define FR(i,n) for(int i=0;i<n;i++)
14 #define MAX 2005
15 #define mkp pair <int,int>
16 using namespace std;
17 const int maxn = 1e6+5;
18 typedef long long ll;
19 const int  inf = 0x3fffff;
20 void read(int  &x) {
21     char ch; bool flag = 0;
22     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == ‘-‘)) || 1); ch = getchar());
23     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
24     x *= 1 - 2 * flag;
25 }
26
27 int ans[maxn];
28 char s1[maxn];
29 int main() {
30     cin>>s1;
31
32     int len = strlen(s1);
33     int st = 0, last = len;
34     for(int i=0;i<len;i++){
35         if(s1[i]==‘r‘){
36             ans[st++]=i+1;
37         }
38         else {
39             ans[--last]=i+1;
40         }
41     }
42     for(int i=0;i<len;i++){
43         printf("%d\n",ans[i]);
44     }
45     return 0;
46 }

原文地址:https://www.cnblogs.com/DreamKill/p/9388196.html

时间: 2024-10-01 18:19:23

Codeforces Round #162 (Div. 1) A. Escape from Stones的相关文章

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 Round #162 (Div. 1) B. Good Sequences (dp+分解素数)

题目:http://codeforces.com/problemset/problem/264/B 题意:给你一个递增序列,然后找出满足两点要求的最长子序列 第一点是a[i]>a[i-1] 第二点 gcd(a[i],a[i-1])>1 也就是说两个数不能互质 找出最长的子序列长度 思路:首先想互质问题,如果两个数互质说明两个数之间没有素因子相同,我们想以每个素因子结尾的最大长度是多少 然后比如样例 2 3 4 6 9 第一个数 2      2结尾 1 第二个数 3      3结尾 1 第三

Codeforces Round #162 (Div. 1) B dp

//存入所有数的素数因数 //若两个数不互质,那么他们之间必然有素数因数 //dp[i][0]表示第i个数不选前i个数中能得到的最长序列 //dp[i][1]表示选了第i个数 //dp[i][0] = max(dp[i-1][0] , dp[i-1][1]) //dp[i][1] = max(dp[pos][1] + 1 ,dp[i][1] ); //pos位第i个数的质数因子出现的最后一个位置 #include<cstdio> #include<cstring> #include

Codeforces Round #162 (Div. 1) C Choosing Balls dp

//dp[i] 表示以颜色为i结尾的最大值 //dp[i] = max(dp[i] , dp[i] + a*v[i] ,other_max + b*v[i]) ; //为除颜色i以外的其它颜色的最大值 #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int maxn = 100010 ; const __int64 inf = 0x7fffffffffff

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #366 (Div. 2) ABC

Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 1 #I hate that I love that I hate it 2 n = int(raw_input()) 3 s = "" 4 a = ["I hate that ","I love that ", "I hate it","I love it"] 5 fo

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿