Shortest and Longest LIS
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的更多相关文章
- [CF1304D] Shortest and Longest LIS - 贪心
看样例,>><>><,要构造 LIS 最短的,我们需要找最小链划分的方案,即包含最少的下降列 很容易想到把连续 < 的看成一段,比如样例就是 .|.|. .| ...
- Codeforces 1304D. Shortest and Longest LIS
根据题目,我们可以找最短的LIS和最长的LIS,找最短LIS时,可以将每一个increase序列分成一组,从左到右将最大的还未选择的数字填写进去,不同组之间一定不会存在s[i]<s[j]的情况, ...
- Codeforces1304D Shortest and Longest LIS
前置扯淡 %%@\(wucstido\),思路是在是巧妙---link Description 给一个长度为\(n\)由 \(<\) 和 \(>\)组成的字符串,表示序列中相邻位置的数的大 ...
- Codeforces 1304D. Shortest and Longest LIS 代码(构造 贪心)
https://codeforces.com/contest/1304/problem/D #include<bits/stdc++.h> using namespace std; voi ...
- Codeforces Round #620 (Div. 2) A-F代码 (暂无记录题解)
A. Two Rabbits (手速题) #include<bits/stdc++.h> using namespace std; typedef long long ll; int ma ...
- Codeforces Round #620 (Div. 2) 题解
A. Two Rabbits 思路: 很明显,如果(y-x)%(a+b)==0的话ans=(y-x)/(a+b),否则就为-1 #include<iostream> #include< ...
- Codeforces Round #620 (Div. 2)
Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳 ...
- LeetCode Number of Longest Increasing Subsequence
原题链接在这里:https://leetcode.com/problems/number-of-longest-increasing-subsequence/description/ 题目: Give ...
- soj 1015 Jill's Tour Paths 解题报告
题目描述: 1015. Jill's Tour Paths Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Every ...
随机推荐
- spring boot 整合mapreduce运行的ClassNotFoundException
问题 一个wordcount运行总是报错 java.lang.RuntimeException: java.lang.ClassNotFoundException: Class com.hadoop. ...
- [总结]一些 DP 优化方法
目录 注意本文未完结 写在前面 矩阵快速幂优化 前缀和优化 two-pointer 优化 决策单调性对一类 1D/1D DP 的优化 \(w(i,j)\) 只含 \(i\) 和 \(j\) 的项--单 ...
- HD Tune检查硬盘各参数的含义
01 =Read Error Rate / (底层)数据读取错误率指从磁盘表面读取数据时发生的硬件读取错误的比率,Raw值对于不同的厂商有着不同的体系,单纯看做1个十进制数字是没有任何意义的.以上为W ...
- Mysql 8.0 新特性测试
Mysql 8.0 新特性测试 Role MySQL8.0版本添加了role特性,role是一种逻辑概念是权限的集合,可以将一个或以上的权限赋予给role,再将role赋给user.Oracle,Po ...
- 测试者出的APP测试面试题
测试者出的APP测试面试题 一.开场问题:(自由发挥) 1.请自我介绍一下: 2.为什么离开上一个公司呢? 3.做测试多久了?以前做过哪些项目?你们以前测试的流程是怎样的?用过哪些测试工具? 4.你觉 ...
- Git - 删除github上的提交历史
参考 https://segmentfault.com/q/1010000002898735 https://stackoverflow.com/questions/1338728/delete-co ...
- ios APP进程杀死之后和APP在后台接收到推送点击跳转到任意界面处理
https://www.jianshu.com/p/ce0dc53eb627 https://www.cnblogs.com/er-dai-ma-nong/p/5584724.html github: ...
- input输入文字的时候背景会变色,如何去掉呢?
默认,如图: 当input框输入文字的时候背景会变色,如图: 有两种方法: 1.在form标签里家这个属性就行: autocomplete="off"
- 泛型和Object的区别?
泛型声明 public <T> T doSomeThing(T t){ return t; } Object声明 public Object doSomeThing(Object obj) ...
- ElementUI 日期选择器 datepicker 选择范围限制
在使用elementUI中日期选择器时,经常会遇到这样的需求——对可选择的时间范围有一定限制,比如我遇到的就是:只能选择今天以前的一年以内的日期. 查阅官方文档,我们发现它介绍的并不详细,下面我们就来 ...