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 ...
随机推荐
- 构造数列Huffman树总耗费_蓝桥杯
快排! /** 问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, pn-1},用这列数构造Huffman树的 ...
- 一大波新款iPhone跟安卓厂商抢夺5G市场
据外媒最新报道称,苹果已经基本完成了今年iPhone的推新阵容,其发布的多款新机中,将涵盖399美元-1149美元的售价区间,特别是5G手机,起步价可能会很亲民,其目的在于进一步占据市场. 今年苹果将 ...
- 华水开学第一课&微信支付
由于疫情的延续,导致我们不能及时开学.只能在网上观看华水开学第一课,但是好像正常开学也没有这个哈哈(不记得了) 昨天没有玩到很晚,12点就睡下.大约半个小时睡着了.定了8点的闹钟.起来的时候那是真的困 ...
- ZooKeeper 相关知识
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/zhang123456456/articl ...
- Vulnhub_DC1 记录
目录 Vulnhub_DC1 记录 经验 & 总结 步骤流水 1. 建立立足点 2. 提权 3. 主机信息搜集 4. 继续提权 5. 消失的flag Vulnhub_DC1 记录 参考walk ...
- HA: Infinity Stones-Write-up
下载地址:点我 哔哩哔哩:点我 主题还是关于复仇者联盟的,这次是无限宝石的. 信息收集 虚拟机的IP为:192.168.116.137 ➜ ~ nmap -sn 192.168.116.1/24 St ...
- Mac OS删除文件夹和文件的命令
https://www.jianshu.com/p/0376bf0514e3 2017.08.18 17:27* 字数 219 阅读 16709评论 0喜欢 0 rmdir删除空目录,不过一旦目录非空 ...
- 4.ORM框架的查询
创建表对应关系代码如下: from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy app=Fl ...
- Vacuum Pump Manufacturer Introduction: Airless Pump Bottle
Fillable vacuum pump bottle with matt silver aluminum base and cap and shiny silver aluminum collar. ...
- Struts2学习(七)
Servlet实现下载 1.Servlet 3.1之前实现文件上传 package ecut.request; import java.io.BufferedReader; import java.i ...