Codeforces 1304D. Shortest and Longest LIS 代码(构造 贪心)

https://codeforces.com/contest/1304/problem/D

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 void solve(){
 4     int n;
 5     string s;
 6     cin>>n;
 7     cin>>s;
 8     int Min[n];
 9     int t = n;
10     for(int i = 0;i<s.length();i++){
11         int len = 0,indx = i;
12         if(s[i] == '<'){
13             while(s[i]=='<'){
14                 len++;
15                 i++;
16             }
17         }
18         for(int j = i;j>=i-len;j--){
19             Min[j] = t,t--;
20         }
21     } 
22     if(t) Min[n-1] = t;
23     t = 1;
24     int Max[n];
25     for(int i = 0;i<s.length();i++){
26         int len = 0,indx = i;
27         if(s[i] == '>'){
28             while(s[i]=='>'){
29                 len++;
30                 i++;
31             }
32         }
33         for(int j = i;j>=i-len;j--){
34             Max[j] = t,t++;
35         }
36     }
37     if(t == n) Max[n-1] = t;
38     for(int i = 0;i<n;i++) cout<<Min[i]<<" ";
39     cout<<endl;
40     for(int i = 0;i<n;i++) cout<<Max[i]<<" ";
41     cout<<endl; 
42 }
43 int main(){
44     int t;
45     cin>>t;
46     while(t--){
47         solve();
48     } 
49     return 0;
50 }
View Code

 

posted @ 2020-02-24 17:28  AaronChang  阅读(225)  评论(0编辑  收藏  举报