Codeforces Round #620 (Div. 2) D
构造一个排列,要求相邻之间的数满足给定的大小关系,然后构造出两个序列,一个序列是所有可能的序列中LIS最长的,一个所有可能的序列中LIS最短的
最短的构造方法:我们考虑所有单调递增的部分,可以发现要让他LIS最小那么就必须要让每一个部分满足前面的比后面的大
最长的构造方法:考虑单调递减的部分,每一个部分都只能选择一个,因此我们要满足后面的部分的值都比前面的大
代码是官方题解的,自己写了半天写不出来
- #include <bits/stdc++.h>
- using namespace std;
- const int MAX_N = 200000;
- int ans[MAX_N + 5];
- int main()
- {
- int tc;
- cin >> tc;
- while (tc--)
- {
- int n, i, j;
- string s;
- cin >> n >> s;
- int num = n, last = 0;
- for (i = 0; i < n; i++)
- {
- if (i == n - 1 || s[i] == '>')
- {
- for (j = i; j >= last; j--)
- ans[j] = num--;
- last = i + 1;
- }
- }
- for (i = 0; i < n; i++)
- cout << ans[i] << (i == n - 1 ? '\n' : ' ');
- num = 1, last = 0;
- for (i = 0; i < n; i++)
- {
- if (i == n - 1 || s[i] == '<')
- {
- for (j = i; j >= last; j--)
- ans[j] = num++;
- last = i + 1;
- }
- }
- for (i = 0; i < n; i++)
- cout << ans[i] << (i == n - 1 ? '\n' : ' ');
- }
- }
Codeforces Round #620 (Div. 2) D的更多相关文章
- Codeforces Round #620 (Div. 2)
Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳 ...
- Codeforces Round #620 (Div. 2) A. Two Rabbits
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a p ...
- Codeforces Round #620 (Div. 2)E LCA
题:https://codeforces.com/contest/1304/problem/E 题意:给定一颗树,边权为1,m次询问,每次询问给定x,y,a,b,k,问能否在原树上添加x到y的边,a到 ...
- Codeforces Round #620 (Div. 2)D dilworld定理
题:https://codeforces.com/contest/1304/problem/D 题意:给定长度为n-1的只含’>'和‘<’的字符串,让你构造出俩个排列,俩个排列相邻的数字之 ...
- 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)E(LCA求树上两点最短距离)
LCA求树上两点最短距离,如果a,b之间距离小于等于k并且奇偶性与k相同显然YES:或者可以从a先走到x再走到y再走到b,并且a,x之间距离加b,y之间距离+1小于等于k并且奇偶性与k相同也输出YES ...
- Codeforces Round #620 (Div. 2)D(LIS,构造)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ io ...
- Codeforces Round #620 (Div. 2) E
LCA的倍增 模板: ], depth[maxn]; int dist[maxn],head[maxn]; void add(int u,int v,int dist0){ a[tot].next=h ...
- Codeforces Round #620 (Div. 2) C. Air Conditioner
Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to ma ...
随机推荐
- C++中类成员变量在初始化列表中的初始化顺序
引子:我们知道,C++中类成员变量的初始化顺序与其在类中的声明顺序是有关的. 先看代码: class TestClass1 { public: TestClass1() { cout << ...
- 【OpenGL】变换矩阵计算公式
摘自: http://ogldev.atspace.co.uk/www/tutorial06/tutorial06.html, http://ogldev.atspace.co.uk/www/tuto ...
- 某oa系统的审计
title: 某oa系统的审计 date: 2018-03-07 17:18:16 tags: --- 信呼OA 闲着没事,java学累了来整理下以前审的一个觉得很有意思的cms,这个作者写的比较灵活 ...
- Python3 (一) 基本类型
前言: 什么是代码? 代码是现实世界事物在计算机世界中的映射. 什么事写代码? 写代码是将现实世界中的事物用计算机语言来描述. 一.数字:整形与浮点型 整型:int 浮点型:float (没有单精度和 ...
- javascript 原生js对html元素的 增删改查 操作
'use strict'; class View{ constructor(){ } //创建html元素 addEl(fel, elemName, id, cls){ //创建一个元素 let el ...
- VFP中OCX控件注册检测及自动注册
这是原来从网上搜集.整理后编制用于自己的小程序使用的OCX是否注册及未注册控件的自动注册函数. CheckCtrlFileRegist("ctToolBar.ctToolBarCtrl.4& ...
- aws 社交媒体技术大会 部分总结
早上会议总结:. 1. 介绍了aws的应用,无技术知识点.略 2. 云原生: 就是一种在云中原生的一种技术 新常态:已经成为一种常态,基本都有的服务都可以部署在云端. 对 “互联网+” 和 “+互联 ...
- Transformer 详解
感谢:https://www.jianshu.com/p/04b6dd396d62 Transformer模型由<Attention is all your need>论文中提出,在seq ...
- 以stm32f407为例,学习cortex-m4通用寄存器的用法
测试代码如下: int add(int a, int b, int c, int d, int e, int f) { return a+b+c+d+e+f; } int main(void) { i ...
- Firewall 防火墙
firewalld和iptables的关系: firewalld自身并不具备防火墙的功能,而是和iptables一样需要通过内核的netfilter来实现.也就是说firewalld和iptables ...