G - Left and Right

With modern technology advancement, it is now possible to deliver mail with a robot! There is a neighborhood on a long horizontal road, on which there are n houses numbered 1 to n from left to right. Every day a mail delivery robot receives a pile of letters with exactly one letter for each house. Due to mechanical restrictions, the robot cannot sort the letters. It always checks the letter on top of the pile, visits the house that should receive that letter and delivers it. The robot repeats this procedure until all the letters are delivered. As a result, each of the n

houses is visited by the robot exactly once during the mail delivery of a single day.

The mail delivery robot has a tracking device that records its delivery route. One day the device was broken, and the exact route was lost. However, the technical team managed to recover the moving directions of the robot from the broken device, which are represented as a string consisting of n−1

letters. The i-th letter of the string is ‘L’ (or ‘R’) if the (i+1)-th house visited by the robot is on the left (or right) of the i-th house visited. For example, if n=4 and the robot visited the houses in the order of 2,4,3,1

, its moving directions would be “RLL”.

With the moving directions, it may be possible to determine the order in which the robot visited the houses. The technical team has asked you to write a program to do that. There can be multiple orders producing the same moving directions, among which you should find the lexicographically earliest order.

Input

The input has a single integer n

(2≤n≤2⋅105) on the first line. The second line has a string of length n−1

consisting of letters ‘L’ and ‘R’ giving the moving directions of the robot.

Output

Output the lexicographically earliest order in which the robot may have visited the houses and delivered the letters according to the moving directions. Consider two different integer sequences of equal length A=(a1,a2,…,ak)

and B=(b1,b2,…,bk), and let 1≤i≤k be the lowest-numbered index where ai≠bi. Then A is lexicographically earlier than B if ai<bi; otherwise B is lexicographically earlier than A

.

Sample Input 1Sample Output 1
3
LR
2
1
3
Sample Input 2Sample Output 2
6
RLLRL
1
4
3
2
6
5
Sample Input 3Sample Output 3
6
RRRLL
1
2
3
6
5
4
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main()
{
    int n;
    cin >> n;
    char str[200005];
    scanf("%s",str+1);
    int pos=1,v=1;
    for(int i=1; i<n; i++)
    {
        if(str[i]=='R')
        {
            for(int j=1; j<=v; j++)
            {
                cout << pos-j+1 << endl;
            }
            pos++;
            v=1;
        }
        else
        {
            v++;
            pos++;
        }
        if(i==n-1)
        {
            for(int j=1; j<=v; j++)
            {
                cout << pos-j+1 << endl;
            }
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
3.4 Pair Interaction Feature The interaction pattern between two individuals is encoded by a spatial descriptor with view invariant relative pose encoding. Given the 3D locations of two individual detec- tions zi,zj and two pose features pi,pj, we represent the pairwise relationship using view normalization, pose co-occurrence encoding, semantic compression and a spatial histogram (see Fig. 5 for illustration). The view normalization is performed by rotating the two people in 3D space by θ with respect to their midpoint, making their connecting line perpendicular to the cam- era view point. In this step, the pose features are also shifted accordingly (e.g. if θ = 45‘, shift 1 dimension with a cycle). Then, the co-occurrence feature is obtained by building a 2-dimensional matrix in which each element (r, c) corresponds to min(pi(r), pj (c)). Although the feature is view invariant, there are still elements in the matrix that deliver the same semantic concepts (e.g. left-left and right-right). To reduce such unnecessary variance and obtain a compact representation, we perform another transformation by multiplying a semantic compression matrix Sc to the vector form of the co-occurrence feature. The matrix Sc is learned offline by enumerating all possible configurations of view points and grouping the pairs that are equivalent when rotated by 180 degrees. Finally, we obtain the pair interaction descriptor by building a spatial histogram based on the 3D distance between the two (bin centers at 0.2, 0.6, 2.0 and 6.5 m). Here, we use linear interpolation similarly to contextual feature in Sec. 3.3. Given the interac- tion descriptor for each pair, we represent the interaction feature φxx(xi,xj) using the confidence value from an SVM classifier trained on a dictionary of interaction labels Y.什么意思
最新发布
07-17

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值