zoukankan      html  css  js  c++  java
  • 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
    ",ans[i]);
    44     }
    45     return 0;
    46 }
    我身后空无一人,我怎敢倒下
  • 相关阅读:
    [洛谷P3403] 跳楼机
    [hdu4630] No Pain No Game
    django-rest-swagger 使用【转】
    Django REST framework入门 (转自中文文档)
    model补充验证钩子函数 性能优化等
    python新动态执行 文件头标识 禁止断言
    Dmango cxrf 自定义分页 缓存 session 序列化 信号量 知识点
    pytho 解析fiddler 导出的har文件代码,自动录入api
    django model 操作总结
    django FBV +CBV 视图处理方式总结
  • 原文地址:https://www.cnblogs.com/DreamKill/p/9388196.html
Copyright © 2011-2022 走看看