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 ...
随机推荐
- ios系统web(微信公众号)开发遇到的问题及解决方案
1.1. 页面滚动不流畅(2017-09-25) 现象: 网页竖向滚动或横向滚动不流畅. 解决方案: 为滚动元素添加css样式: -webkit-overflow-scrolling: touch; ...
- JDBC模板CRUD
创建一个Util工具类 创建工具类为了方便后期管理,例如对数据库做出修改的时候只需要在工具类里修改一处即可! import java.sql.Connection; import java.sql.D ...
- 关于spring cloud “Finchley.RC2”版本在spring cloud config中的ArrayIndexOutOfBoundsException
原文 https://www.cnblogs.com/Little-tree/p/9166382.html 在学spring cloud config的时候遇到一个ArrayIndexOutOfBou ...
- core_cm4.h(129): error: #35: #error directive: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
今天使用 systick 的时候,只使用了头文件 core_cm4.h,结果就报错了,原因是 __FPU_PRESENT 没有定义,这个定义其实在 stm32f4xx.h 里面.所以如果要解决这个错误 ...
- 实验吧Web-难-头有点大(http头伪造:浏览器、国家、.Net framework版本)
进去网站显示: 此处告诉我们要干三件事: (1).net framework 版本为9.9 (2)告诉服务器我们的地址为英国 (3)我们访问站点用的是IE 下面我们就抓的包中伪造. 1:.net fr ...
- 实现VR直播的关键技术
VR是多媒体技术发展的必然趋势,人们所使用的信息载体从最早的文字.图像,到音视频,再到用VR,将事物的描述表达推向了极致,充分满足了沉浸性.互动性和构想性三大要素的需求.随着5G的商业化运营,VR有望 ...
- Maven - 构建生命周期、阶段、目标
版权所有,未经授权,禁止转载 章节 Maven – 简介 Maven – 工作原理 Maven – Repository(存储库) Maven – pom.xml 文件 Maven – 依赖管理 Ma ...
- 快速排序_python
def quicksort(ls,result): if len(ls)<=1: result+=ls # return result else: flag=ls[0] left=[x for ...
- vector删除指定元素
#pragma once #include "stdafx.h" #include<windows.h> #include <vector> #includ ...
- python获取页面文字信息
# -*- coding: utf- -*- from selenium import webdriver import time, re,requests,os,time,random,traceb ...