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 ...
随机推荐
- PHPStorm 使用 Xdebug
一.下载xdebug xdebug官网:https://xdebug.org/download.php 在选择下载哪个版本的xdebug的时候需要注意了,下面有两种方法,让你准确的下载自己环境对应的x ...
- 高级T-SQL进阶系列 (一)【中篇】:使用 CROSS JOIN 介绍高级T-SQL
[译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文连接:传送门. 当一个CROSS JOIN 表现得如同一个INNER JOIN 在上一章节我提到当你使用一个CROSS JOIN ...
- C++11常用特性介绍——decltype关键字
一.decltype的意义 有时我们只想从表达式的类型推断出要定义的变量类型,但是不想用其值进行初始化的时候,C++11新标准引入了decltype类型说明符,它的作用是选择并返回操作数的数据类型,在 ...
- MySQL中case when的基本用法总结
MySQL中case when的基本用法总结原创Backcanhave7 最后发布于2018-12-06 15:14:15 阅读数 439 收藏展开MySQL中的case when有用两种用法,官方文 ...
- python闯关之路一(语法基础)
1,什么是编程?为什么要编程? 答:编程是个动词,编程就等于写代码,那么写代码是为了什么呢?也就是为什么要编程呢,肯定是为了让计算机帮我们搞事情,代码就是计算机能理解的语言. 2,编程语言进化史是 ...
- 「JSOI2011」柠檬
「JSOI2011」柠檬 传送门 斜率优化题. 在优化前,还有一个值得一提的优化: 对于最后的最优分割方案,每一段的两个端点一定是同颜色的,并且作为这一段的 \(s_0\) 证明:如果不作为这一段的 ...
- python中:from * import 与 import 详解
在python 中导入模块是我们最常用的功能,基本每个.py 文件中都会有 import 或者是 from * import 语句,可是,这两种方法有什么不同,有该怎么用?今天就好好分析一下. 先上定 ...
- @implementer,抽象类,接口
@implementer,抽象类,接口 1. implementer 在看twisted源码时,经常出现@implementer(IReactorFDSet) 它来自zope.interfa ...
- Session共享解决方案
使用nginx做的负载均衡添加一个ip_hash配置 一.开两个Tomcat写测试程序 @WebServlet("/nginxSessionServlet") public cla ...
- jQuery常用操作(待续)
1. input清空内容 <1> $("#选择器id").val(""); <2> $("input[name='input框 ...