Codeforces1304D Shortest and Longest LIS
前置扯淡
%%@\(wucstido\),思路是在是巧妙---link
Description
给一个长度为\(n\)由 \(<\) 和 \(>\)组成的字符串,表示序列中相邻位置的数的大小关系
求构造两种排列,使得其在满足上述条件的情况下的 \(LIS\) 分别最长\(/\)最短
Solution
直接考虑构造最短的排列,然后最长的同理(真的是把符号改改就可以了)
整个排列\(LIS\)的最小值在最长的一段\("<"\)中取得,然后我们考虑构造
先把整个排列逆序过来:即 \(a_i=n-i+1\)
然后对于每一个\("<"\),翻转相邻的数字
正确性显然(真的是很巧妙!!!!!!)
最长的构造就是初始化正序,大于号翻转!就完事啦!!
别想复杂了,构造题就是构造题
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
const int N=2e5+10;
char s[N]; int ans[N],n;
inline void work()
{
n=read(); scanf("%s",s+1);
for(int i=1;i<=n;++i) ans[i]=n-i+1;
for(int i=1;i<n;++i)
{
int j=i; while(s[j]=='<') ++j; reverse(ans+i,ans+j+1); i=j;
} for(int i=1;i<=n;++i) printf("%lld ",ans[i]); puts("");
for(int i=1;i<=n;++i) ans[i]=i;
for(int i=1;i<n;++i)
{
int j=i; while(s[j]=='>') ++j; reverse(ans+i,ans+j+1); i=j;
} for(int i=1;i<=n;++i) printf("%lld ",ans[i]); puts("");
return ;
}
signed main()
{
int T=read(); while(T--) work();
return 0;
}
}
signed main(){return yspm::main();}
Codeforces1304D Shortest and Longest LIS的更多相关文章
- Shortest and Longest LIS
Codeforces Round #620 (Div. 2) D. Shortest and Longest LIS 题解: 贪心即可,对于最短序列,我们尽可能用可用的最大数字放入序列中,对于最长序列 ...
- [CF1304D] Shortest and Longest LIS - 贪心
看样例,>><>><,要构造 LIS 最短的,我们需要找最小链划分的方案,即包含最少的下降列 很容易想到把连续 < 的看成一段,比如样例就是 .|.|. .| ...
- Codeforces 1304D. Shortest and Longest LIS
根据题目,我们可以找最短的LIS和最长的LIS,找最短LIS时,可以将每一个increase序列分成一组,从左到右将最大的还未选择的数字填写进去,不同组之间一定不会存在s[i]<s[j]的情况, ...
- 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 ...
随机推荐
- tomcat迁移到weblogic的几个问题
第1个问题: 异常描述:VALIDATION PROBLEMS WERE FOUND problem: cvc-enumeration-valid: string value '3.0' is not ...
- Java学习笔记(一) 面向对象---封装
面向对象---封装 封装是面向对象思想的三大特征之一. 理解: 隐藏对象的属性和实现细节,仅对外提供公共访问方式. 优点: 将变化隔离 便于使用 提升代码复用性 提高安全性 封装原则: 将不需要对外提 ...
- Activity LauchMode设置
lauchMode: standard: 标准模式,每次调用startActivity()方法就会产生一个新的实例. singleTop: 如果已经有一个实例位于Activit ...
- PAT Advanced 1155 Heap Paths (30) [DFS, 深搜回溯,堆]
题目 In computer science, a heap is a specialized tree-based data structure that satisfies the heap pr ...
- [转]Linux命令行上传文件到 百度网盘 bypy
安装软件工具: apt-get install python-pip pip install requests pip install bypy 授权登陆: 执行 bypy info,显示下边信息,根 ...
- js事件函数中function(e){}
简单来说就是指向了当前发生的事件(click.mouseover等等),保存了当前事件的信息.如鼠标点击事件,有鼠标的坐标信息.其中,e是标准浏览器传递进去的事件参数,低版本IE不会传递,事件参数放置 ...
- openstack trove 数据库镜像构建列表
文件位置:/trove/integration/scripts/files/elements ubuntu@ubuntu:~/Downloads/trove/integration/scripts/f ...
- 第21章—websocket
spring boot 系列学习记录:http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址:https://gitee.com/jinxia ...
- VUE- iView组件框架的使用
VUE- iView组件框架的使用 1. 下载iView 工程. 引用:https://www.iviewui.com/
- python3编码问题个人理解
#coding=utf-8 a = "你" # 这个字符串是Unicode和 a = u“你”等价b = b'\\u4f60' #这个表示b是字节串(如果需要显示b的值则 prin ...