智商压制篇:“构造,又是构造!”链接:http://codeforces.com/contest/1304/problem/D
题意:输出两行,每行数字范围是1~n,第一行最短LIS,第二行最长LIS。
题解:最长、最短LIS相同情况只有一种:“全是<” 或者 “全是>”。
其他的只要有一个符号不同,就会有很多种组合方式。
每一次符号改变都是一次转折点,围绕这一点进行分块!
最短LIS:尽可能把最大的数字往最前放,
最长LIS:尽可能把最小的数字往最前放。
#include<iostream>
#include <string>
#include <string.h>
using namespace std;
int n;
string s;
int a[200005],b[200005];
void solve()
{
int top=0,num=n;
//最短LIS
for(int i=0;i<n;i++)
{
if(i==n-1||s[i]=='>')
{
for(int j=i;j>=top;j--)
a[j]=num--;
top=i+1;
}
}
top=0,num=1;
//最长LIS
for(int i=0;i<n;i++)
{
if(i==n-1||s[i]=='<')
{
for(int j=i;j>=top;j--)
b[j]=num++;
top=i+1;
}
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>s;
solve();
for(int i=0;i<n;i++)
printf("%d ",a[i]);
cout<<endl;
for(int i=0;i<n;i++)
printf("%d ",b[i]);
cout<<endl;
}
return 0;
}