Codeforces Round #162 (Div. 1) A. Escape from Stones
Posted dreamkill
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #162 (Div. 1) A. 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.
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 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 ",ans[i]); 44 } 45 return 0; 46 }
以上是关于Codeforces Round #162 (Div. 1) A. Escape from Stones的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #162 (Div. 1) B. Good Sequences (dp+分解素数)
Codeforces Round #436 E. Fire(背包dp+输出路径)
[ACM]Codeforces Round #534 (Div. 2)