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;
}

 

在MATLAB中,你可以使用`patch`、`surf`或`contour`等函数来绘制三维函数的可行域。对于给定的三个二维函数 \( g = (x - 2)^2 + y^2 - 9 \), \( h = (x + 2)^2 + y^2 - 25 \), 和 \( f = (x - 3)^2 + (y + 5)^2 \),它们分别代表的是圆心在点(2,0)、(-2,0)和(3,-5)的两个半径为3和5的圆以及一个位于这两个圆之间的点(3,-5)处的圆。为了绘制这些函数的交集区域(即可行域),可以考虑以下步骤: 首先,你需要创建一个二维网格 `X` 和 `Y`,通常范围可以设置为函数可能达到值的地方,例如 `-10:0.1:10` 对于每个维度。 ```matlab [X, Y] = meshgrid(-10:.1:10, -10:.1:10); ``` 然后,计算每个函数的值并将其小于等于零的部分设为1(表示在该区域内),大于零的部分设为0(表示不在区域内)。 ```matlab g_values = (X - 2).^2 + Y.^2 - 3).^2 + (Y + 5).^2; % 将大于0的值设为0,小于等于0的值设为1 g_mask = g_values <= 0; h_mask = h_values <= 0; f_mask = f_values <= 0; % 结合三个函数的约束 feasible_region = logical_or(g_mask, h_mask); % 仅保留g和h的交集 feasible_region = logical_and(feasible_region, f_mask); % 再加上f的约束 ``` 最后,你可以使用 `surf(X, Y, feasible_region)` 或者 `colormap(gray)` 来可视化这个可行域,`surf`会高亮显示可行区域,而 `colormap(gray)` 可以让颜色更明显地区分区域。 ```matlab surf(X, Y, feasible_region, 'FaceColor', [0.8 0.8 0.8]); % 高亮区域 colormap(gray); % 使用灰度图 xlabel('x'); ylabel('y'); zlabel('Feasibility'); title('Intersection of the Three Functions'); % 显示所有三个函数的轮廓线 hold on; contour(X, Y, g_values, [0]); contour(X, Y, h_values, [0]); contour(X, Y, f_values, [0], 'LineWidth', 2); legend('Feasible Region', 'g = 0', 'h = 0', 'f = 0'); hold off; ``` 别忘了运行`view(2)`或者`view(3)`来查看从不同角度的效果。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值