zoukankan      html  css  js  c++  java
  • codeforces 1304D Shortest and Longest LIS

    题目链接:http://codeforces.com/problemset/problem/1304/D

    思路:

    最短的LIS:n,n-1,n-2,...3,2,1

    最长的LIS:1,2,3,...,n-2,n-1,n

    我们可以再按照给定字符串的大小关系,对两种LIS进行区间排序即可。

    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <functional>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    #define ll long long
    #define pb push_back
     
    const int N = 2e5+10;
    vector<int > vi;
    ll a[N];
     
    void show(int x){
        for(int i = 0; i < x; ++i) cout << a[i] << " ";
        cout << endl;
    }
     
    void solve(){
     
        int n;
        string str;
        cin >> n >> str;
        int _end = str.length();
        for(int i = 0; i < n; ++i) a[i] = n-i;
        int l = 0,r = 0;
        while(l < _end){
            if(str[l] == '>'){
                ++l; continue;
            }
            for(int i = l; i < _end; ++i){
                if(str[i] == '<') r = i;
                else break;
            }
            //cout << l << "   " << r << endl;
            sort(a+l,a+r+2);
     
            l = r+1;
        }
        for(int i = 0; i < n; ++i) cout << a[i] << " ";
        cout << endl;
        for(int i = 0; i < n; ++i) a[i] = i+1;
        l = r = 0;
        while(l < _end){
            if(str[l] == '<'){
                ++l; continue;
            }
            for(int i = l; i < _end; ++i){
                if(str[i] == '>') r = i;
                else break;
            }
            //cout << l << "   " << r << endl;
            sort(a+l,a+r+2,[](int a,int b){return a > b;});
            l = r+1;
        }
        for(int i = 0; i < n; ++i) cout << a[i] << " ";
        cout << endl;
    }
     
    int main(){
     
        int T;
        cin >> T;
        for(int i = 0; i < T; ++i){
            solve();
        }
     
        return 0;
    }
  • 相关阅读:
    Linux 防火墙配置
    【存在问题,待修改】SSH 远程登陆
    Hadoop 本地模式安装
    CentOS7 安装 JDK
    JS的DOM操作
    JavaScript
    格式与布局(定位)
    样式表
    表单、内嵌网页
    HTML中的一般标签、常用标签和表格
  • 原文地址:https://www.cnblogs.com/SSummerZzz/p/12378436.html
Copyright © 2011-2022 走看看