跳到正文

个人记录

9.8周二下午--河西--蒋:双端队列

HAHA66666约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年9月11日
收录
2026年9月11日
更新
2026年11月11日
篇幅
约 1 分钟

版本

  1. v1当前

T1

这题其实想通了就很简单,思路是这样的:把整道题反过来做,for循环从后往前操作,往前插入变往后,往后插入变往前插入。

总之,代码是这样的:

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int n;
string s;
deque<int>dl;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>s;
	dl.push_back(n);
	for(int i=n-1;i>=0;i--){
		if(s[i]=='L'){
			dl.push_back(i);
		}else{
			dl.push_front(i);
		}
	}
	for(auto i:dl)cout<<i<<' ';
	return 0;
}
原文