Atcoder(134)E - Sequence Decomposing
E - Sequence Decomposing
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 500500 points
Problem Statement
You are given a sequence with NN integers: A={A1,A2,⋯,AN}A={A1,A2,⋯,AN}. For each of these NN integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:
- If AiAi and AjAj (i<j)(i<j) are painted with the same color, Ai<AjAi<Aj.
Find the minimum number of colors required to satisfy the condition.
Constraints
- 1≤N≤1051≤N≤105
- 0≤Ai≤1090≤Ai≤109
Input
Input is given from Standard Input in the following format:
NN
A1A1
::
ANAN
Output
Print the minimum number of colors required to satisfy the condition.
Sample Input 1 Copy
5
2
1
4
5
3
Sample Output 1 Copy
2
We can satisfy the condition with two colors by, for example, painting 22 and 33 red and painting 11, 44, and 55 blue.
Sample Input 2 Copy
4
0
0
0
0
Sample Output 2 Copy
4
We have to paint all the integers with distinct colors.
题意:给定一个数字串,按照从前往后从小到大进行组合,最少能组合成几条这样的数字串。
利用STL进行模拟
数据范围是1e5,时间是2s,则算法需要nlgn
通过二分法进行查找,和for遍历一遍
算法1:
将数字串全部-1,进行反转,转化成从前往后从大到小进行组合;
通过vector数组进行模拟,利用upper_bound()进行查找在其前边比其 大的值进行替换为本值,没有比其大的值就push_back()此值,拿此值作为另一串的开头。
//lower_bound()和upper_bound()的区别
时间复杂度都是lgn
lower_bound(a.begin(),a,end(),key) 是查找大于等于key的位置
upper_bound(a.begin(),a.end(),key)是查找大于key 的位置
#include<iostream>
#include<vector>
#include<algorithm> using namespace std; int main ()
{
int n;
cin>>n;
int a;
vector<int>b;
while(n--)
{
cin>>a;
a*=-1;
int it=upper_bound(b.begin(),b.end(),a)-b.begin();
if(it==b.size())
{
b.push_back(a);
}
else
b[it]=a; }
cout<<b.size()<<endl;
return 0;
}
算法2:利用deque//双端队列(速度非常快)
#include<iostream>
#include<deque>
using namespace std; int main ()
{
int n;
cin>>n;
int a;
deque<int>b;
for(int i=0;i<n;i++)
{
cin>>a;
int it= lower_bound(b.begin(),b.end(),a)-b.begin();
if(!it)
b.push_front(a);
else
b[it-1]=a;
}
cout<<b.size()<<endl; return 0;
}
Atcoder(134)E - Sequence Decomposing的更多相关文章
- AtCoder Beginner Contest 134-E - Sequence Decomposing
(https://atcoder.jp/contests/abc134/tasks/abc134_e) 题意:找出最小个数的最长上升子序列 思路:找出最长上升子序列的最小个数,只需要找出每个最小上升子 ...
- Atcoder E - RGB Sequence(dp)
题目链接:http://arc074.contest.atcoder.jp/tasks/arc074_c 题意:一共有3种颜色,红色,绿色,蓝色.给出m个要求l,r,x表示在区间[l,r]内要有x种不 ...
- AtCoder AGC031D A Sequence of Permutations (群论、置换快速幂)
题目链接 https://atcoder.jp/contests/agc031/tasks/agc031_d 题解 这居然真的是个找规律神题... 首先要明白置换的一些基本定义,置换\(p\)和\(q ...
- AtCoder - 2567 RGB Sequence
Problem Statement There are N squares arranged in a row. The squares are numbered 1, 2, …, N, from l ...
- AtCoder - 3962 Sequence Growing Hard
Problem Statement Find the number of the possible tuples of sequences (A0,A1,…,AN) that satisfy all ...
- AtCoder Regular Contest 074 E:RGB Sequence
题目传送门:https://arc074.contest.atcoder.jp/tasks/arc074_c 题目翻译 给你一行\(n\)个格子,你需要给每个格子填红绿蓝三色之一,并且同时满足\(m\ ...
- AtCoder Grand Contest 003 E - Sequential operations on Sequence
题目传送门:https://agc003.contest.atcoder.jp/tasks/agc003_e 题目大意 一串数,初始为\(1\sim N\),现有\(Q\)个操作,每次操作会把数组长度 ...
- Atcoder Grand Contest 024 E - Sequence Growing Hard(dp+思维)
题目传送门 典型的 Atcoder 风格的计数 dp. 题目可以转化为每次在序列中插入一个 \([1,k]\) 的数,共操作 \(n\) 次,满足后一个序列的字典序严格大于前一个序列,问有多少种操作序 ...
- Atcoder Grand Contest 031 D - A Sequence of Permutations(置换+猜结论)
Atcoder 题面传送门 & 洛谷题面传送门 猜结论神题. 首先考虑探究题目中 \(f\) 函数的性质,\(f(p,q)_{p_i}=q_i\leftarrow f(p,q)\circ p= ...
随机推荐
- 【Java基础】面向对象上
面向对象上 这一章主要涉及 Java 类及类的成员,包括属性.方法.构造器:代码块.内部类. 面向过程与面向对象 面向过程(Procedure Oriented Programming,POP)与面向 ...
- 根据业务摸索出的一个selenium代码模版(python)
前言 总算入行上班几个月了,不得不说业务是真的不消停啊.. 本人工作上经常遇到一种场景:为甲方做自动化接口处理工具,登录需要短信验证码,, 嘛算是摸索出了一套selenium代码模板,主要解决如下痛点 ...
- 【ORACLE】11g rac+dg
首先感谢群友分享的文档,在这里先感谢哆啦B梦,非常感谢 该文档主要指导如何利用现有的RAC环境搭建一套RAC与单实例的DG的环境 ============================主机配置信息 ...
- File Inclusion - Pikachu
概述: 文件包含,是一个功能.在各种开发语言中都提供了内置的文件包含函数,其可以使开发人员在一个代码文件中直接包含(引入)另外一个代码文件. 比如 在PHP中,提供了: include(),inclu ...
- 史上最全postgreSQL体系结构(转)
原文链接:https://cloud.tencent.com/developer/article/1469101 墨墨导读:本文主要从日志文件.参数文件.控制文件.数据文件.redo日志(WAL).后 ...
- [XAML] 使用 XAML 格式化工具:XAML Styler
1. XAML 的问题 刚入门 WPF/UWP 之类的 XAML 平台,首先会接触到 XAML 这一新事物.初学 XAML 时对它的印象可以归纳为一个词:一坨. 随着我在 XAML 平台上工作的时间越 ...
- 国内最具影响力科技创投媒体36Kr的容器化之路
本文由1月19日晚36Kr运维开发工程师田翰明在Rancher技术交流群的技术分享整理而成.微信搜索rancher2,添加Rancher小助手为好友,加入技术群,实时参加下一次分享~ 田翰明,36Kr ...
- Python 身份证校验代码
Python 身份证校验代码 居民身份证bai编号识别 1.身份证编码规则如下:根据[中华人民共和国国家标准GB11643-1999]中有关公民身份号码的规定,公民身份号码是特征组合码,由十七位数字本 ...
- python3多进程 进程池 协程并发
一.进程 我们电脑的应用程序,都是进程,进程是资源分配的单位.进程切换需要的资源最大,效率低. 进程之间相互独立 cpu密集的时候适合用多进程 #多 ...
- 获取控制台的错误信息 onerror
js 获取控制台的错误信息 https://www.bbsmax.com/A/Vx5ML2NmJN/ <!DOCTYPE html> <html lang="en" ...