[字符串] cf 1304 D

题目

在这里插入图片描述

题目链接:https://codeforces.com/contest/1304/problem/D

思路

题目大意是分别输出由1到n数字组成的字符串最少的和最多的最长上升子序列。
我好懒的写题解哦。

代码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
int a[200010],b[200010];
bool vis1[200010],vis2[200010];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int cnt=n+1;
		for(int i=1;i<=n;i++){
			int t=i;
			while(s[t-1]=='<') ++t;
			for(int j=t;j>=i;j--) a[j]=--cnt;
			i=t;
		}
		for(int i=1;i<=n;i++) cout<<a[i]<<" \n"[i==n];
		cnt=0;
		for(int i=1;i<=n;i++){
			int t=i;
			while(s[t-1]=='>') ++t;
			for(int j=t;j>=i;j--) b[j]=++cnt;
			i=t;
		}
		for(int i=1;i<=n;i++) cout<<b[i]<<" \n"[i==n];
	}
    return 0;
}

发布了78 篇原创文章 · 获赞 1 · 访问量 4389

猜你喜欢

转载自blog.csdn.net/kosf_/article/details/104344950