题意:
t组数据,每组一个n,一个n-1长度的字符串,只有 < > ,第i个的<是第i个数<第i+1个数,要求用1~n的数构造出两个序列,且其中一个lis最小,另一个lis最大。
思路:
如果只要求构造出来就很简单,直接建图,跑一边拓扑就行了,但这里要让lis最大和最小。
所以要用一个贪心的思想来。
求最小,肯定尽可能的让他们不能形成上升,所以我们就把大的往前面放,从左到右每次贪心去最大就行了(取的同时满足限制)。
求最大,也是让他们尽可能形成上升序列,所以我们把小的往前面放,从左到右每次贪心去最大就行了(取的同时满足限制)。
code
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;
char str[man];
int a[man],b[man];
int main() {
#ifndef ONLINE_JUDGE
//freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif
int t;
cin >> t;
while(t--){
int n;
cin >> n >> str;
int ans = n,pre = 0;
for(int i = 0;i < n;i++){
if(str[i]=='>'||i==n-1){
for(int j = i;j >= pre;j--){
a[j] = ans;
ans--;
}
pre = i + 1;
}
}
ans = 1,pre = 0;
for(int i = 0;i < n;i++){
if(str[i]=='<'||i==n-1){
for(int j = i;j >= pre;j--){
b[j] = ans;
ans++;
}
pre = i + 1;
}
}
for(int i = 0;i < n;i++)cout << a[i] << " ";
cout << endl;
for(int i = 0;i < n;i++)cout << b[i] << " " ;
cout << endl;
}
return 0;
}