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 ...
随机推荐
- requests 用法小速记
Request库安装方法 Request官网 使用管理员权限启动 command控制台(win+X 命令提示符(管理员)) 使用pip安装requests库(默认配置好python以及pip的环境变量 ...
- SpringMVC 入门demo
(1)新建Spring项目 (2)添加所需要的jar包 spring的5+2: spring-core.jar spring.beans.jar spring-context.jar spring-e ...
- kafka2x-Elasticsearch 数据同步工具demo
Bboss is a good elasticsearch Java rest client. It operates and accesses elasticsearch in a way simi ...
- Python爬虫解析网页的4种方式 值得收藏
用Python写爬虫工具在现在是一种司空见惯的事情,每个人都希望能够写一段程序去互联网上扒一点资料下来,用于数据分析或者干点别的事情. 我们知道,爬虫的原理无非是把目标网址的内容下载下来存储到内存 ...
- S32K144之时钟配置
一般来说,时钟精度.稳定性取决于所采用的时钟源,就MCU S32K来说如内部振荡器SIRC,FIRC,128KLPO,外部晶振等,跟所使用的外设(FTM, LPIT,LPT,RTC等)和哪一路输出时钟 ...
- Apache+Php+Mysql配置
软件工具:(下载时注意下载相应版本,不同版本安装细节可能会有差异!!) 1>httpd-2.4.18-win64-VC14.zip 下载地址: http://www.apachelounge.c ...
- matlab学习 — 实现简单的爬虫
这里复杂的情况暂时不考虑..测试网址为pixiv的每日排行榜 = = url = 'https://www.pixiv.net/ranking.php?mode=daily' text = webre ...
- python学习 —— 字符画
代码: import os from PIL import Image WIDTH = int(250) HEIGHT = int(250/2) ascii_char = list('toahkbdp ...
- 解题报告:luogu P1196 [NOI2002]银河英雄传说
由于并查集让我很自闭(其实是我太弱了),所以学习了加权并查集,这是例题: 题目链接:P1196 [NOI2002]银河英雄传说 不是很简单,但对于大佬还是签到题. 合并与路径压缩时直接维护\(dis[ ...
- zookeeper和eureka的区别在哪?
zookeeper和eureka的区别在哪?传统的关系型数据库是ACID(原子性,一致性,独立性,持久性), nosql数据库是CAP(强一致性,可用性,分区容错性),分布式系统只能3进2,三个选两个 ...