Codeforces Round #620 (Div. 2)

D. Shortest and Longest LIS

题解:

贪心即可,对于最短序列,我们尽可能用可用的最大数字放入序列中,对于最长序列,我们尽可能用可用的最小数组放入序列即可,再处理序列时,当满足当前防止变化规律的符号直接防止,如果不满足则向后遍历直到遇到满足条件的符号,然后倒序放直到放完。eg. “><<>” 我们从大向小取,第一个为大于号所以直接填入,第二为小于号暂时不填,第三为小于号暂时不填,第四个为大于号,开始填,直到填到第二位结束,最后一个放在最后即可。

/**********************************************************
* @Author: Maple
* @Date: 2020-02-24 16:40:40
* @Last Modified by: Maple
* @Last Modified time: 2020-02-24 16:49:03
* @Remark:
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std; typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll; const int maxn=2e5+100;
int n,ans[maxn];
char str[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
int t;
cin>>t;
while(t--){
cin>>n;
cin>>str;
int num=n,ls=0;
//最短排列
for(int i=0;i<n;i++){
if(str[i]=='>'||i==n-1){
for(int j=i;j>=ls;j--){
ans[j]=num--;
}
ls=i+1;
}
}
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
num=1,ls=0;
//最长排列
for(int i=0;i<n;i++){
if(str[i]=='<'||i==n-1){
for(int j=i;j>=ls;j--){
ans[j]=num++;
}
ls=i+1;
}
}
for(int i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}

Shortest and Longest LIS的更多相关文章

  1. [CF1304D] Shortest and Longest LIS - 贪心

    看样例,>><>><,要构造 LIS 最短的,我们需要找最小链划分的方案,即包含最少的下降列 很容易想到把连续 < 的看成一段,比如样例就是 .|.|. .| ...

  2. Codeforces 1304D. Shortest and Longest LIS

    根据题目,我们可以找最短的LIS和最长的LIS,找最短LIS时,可以将每一个increase序列分成一组,从左到右将最大的还未选择的数字填写进去,不同组之间一定不会存在s[i]<s[j]的情况, ...

  3. Codeforces1304D Shortest and Longest LIS

    前置扯淡 %%@\(wucstido\),思路是在是巧妙---link Description 给一个长度为\(n\)由 \(<\) 和 \(>\)组成的字符串,表示序列中相邻位置的数的大 ...

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

    https://codeforces.com/contest/1304/problem/D #include<bits/stdc++.h> using namespace std; voi ...

  5. Codeforces Round #620 (Div. 2) A-F代码 (暂无记录题解)

    A. Two Rabbits (手速题) #include<bits/stdc++.h> using namespace std; typedef long long ll; int ma ...

  6. Codeforces Round #620 (Div. 2) 题解

    A. Two Rabbits 思路: 很明显,如果(y-x)%(a+b)==0的话ans=(y-x)/(a+b),否则就为-1 #include<iostream> #include< ...

  7. Codeforces Round #620 (Div. 2)

    Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳 ...

  8. LeetCode Number of Longest Increasing Subsequence

    原题链接在这里:https://leetcode.com/problems/number-of-longest-increasing-subsequence/description/ 题目: Give ...

  9. soj 1015 Jill's Tour Paths 解题报告

    题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...

随机推荐

  1. 杭电 1059 Dividing

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. Jedis实现频道的订阅,取消订阅

     第一步:创建一个发布者 package work; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; i ...

  3. mxgraph初体验

    最近公司让学习了mxgraph,简单总结一下 (1)mxGraph学习路径 1)API:http://jgraph.github.io/mxgraph/docs/js-api/files/index- ...

  4. DoublyLinkedList(双向链表)

    本来还不会写双向链表的,但最近学习了二叉树后,突然意识到这不就是双向链表嘛,然后通过对二叉树的理解,实现了一下双向链表. 代码: #define SIZE 10 DouLL * head, *n, * ...

  5. SpringBoot 集成JUnit

    项目太大,不好直接测整个项目,一般都是切割成多个单元,单独测试,即单元测试. 直接在原项目上测试,会把项目改得乱七八糟的,一般是单独写测试代码. 进行单元测试,这就需要集成JUnit. (1)在pom ...

  6. Windows驱动开发-DPC定时器

    DCP是一种使用更加灵活的定时器,可以对任意间隔时间进行定时.DPC定时器的内部使用了一个定时器对象KTIMER,当你设定了定时器之后,从设定开始起经过这个时间之后操作系统会将一个DPC定时器的例程插 ...

  7. LeetCode 680. Valid Palindrome II(双指针)

    题意:给定一个字符串,可以最多去掉一个字符,判断是否可以使该字符串成为一个回文串. 分析:head和tail双指针分别指向字符串首尾,如果s[head] != s[tail],则要么去掉s[head] ...

  8. Python学习第十七课——组合

    组合1 #组合 1 class Hand: pass class Foot: pass class Trunk: pass class Head: pass class Person: def __i ...

  9. FineReport帆软报表需求:根据url传递过来的参数值决定显示隐藏列

    需求:角色id传递到报表页面中,然后根据角色id,决定隐藏第1列,显示第2-4列,还是隐藏第2-4列,显示第1列. 解决方法:

  10. get your sqlserver database back by using EMC NW NMM

    Dear all Yes ~ We can backup our sqlserver by EMC NW NMM. That is true and NW is a very very powerfu ...