当前位置:网站首页>acwing 2816. Judgement subsequence
acwing 2816. Judgement subsequence
2022-06-12 16:18:00 【_ Liuxiaoyu】
Given a length of n Integer sequence of a1,a2,…,an And a length of m Integer sequence of b1,b2,…,bm.
Please judge a Whether the sequence is b Subsequences of sequences .
Subsequence refers to the sequence obtained by arranging some items of the sequence in the original order , For example, the sequence {a1,a3,a5} It's a sequence {a1,a2,a3,a4,a5} A subsequence of .
Input format
The first line contains two integers n,m.
The second line contains n It's an integer , Express a1,a2,…,an.
The third line contains m It's an integer , Express b1,b2,…,bm.
Output format
If a Sequence is b Subsequences of sequences , Output one line Yes.
otherwise , Output No.
Data range
1≤n≤m≤105,
−109≤ai,bi≤109
sample input :
3 5
1 3 5
1 2 3 4 5
sample output :
Yes
Double pointer algorithm : It's easy to think of .
code:
#include <iostream>
using namespace std;
const int N = 100010;
int n, m;
int a[N], b[N];
int main()
{
cin >> n >> m;
for(int i =0 ;i < n; i ++) cin >> a[i];
for(int i =0; i < m; i ++) cin >> b[i];
int i = 0, j = 0;
while(i < n && j < m)
{
if(a[i] == b[j]) i ++;
j ++;
}
if(i == n) cout << "Yes";
else cout << "No";
return 0;
}
Or write like this
#include <iostream>
using namespace std;
const int N = 100010;
int n, m;
int a[N], b[N];
int main()
{
cin >> n >> m;
for(int i =0 ;i < n; i ++) cin >> a[i];
for(int i =0; i < m; i ++) cin >> b[i];
int j = 0;
for(int i = 0; i < m && j < n; i ++)
{
if(a[j] == b[i]) j ++;
}
//cout << j << endl;
if(j == n ) cout << "Yes";
else cout << "No";
return 0;
}
边栏推荐
- Global and Chinese markets for air sampling calibration pumps 2022-2028: Research Report on technology, participants, trends, market size and share
- Batch --04--- moving components
- acwing788. 逆序对的数量
- [weekly replay] game 80 of leetcode
- The market share of packaged drinking water has been the first for eight consecutive years. How does this brand DTC continue to grow?
- 聊聊事件监听那些事-上
- From K-means to capsule
- acwing 800. 数组元素的目标和
- 联通网管协议框图
- The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.3 open、creat、close、unlink
猜你喜欢

acwing 800. 数组元素的目标和

一步步创建包含自定义 Screen 的 ABAP 程序的详细步骤

< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(三)

Read MHD and raw images, slice, normalize and save them

The common hand, the original hand and the excellent hand from the sum of Fibonacci sequence

acwing 801. 二进制中1的个数(位运算)

Thinking about the probability of drawing cards in the duel link of game king

Redis string type common commands

Step by step steps to create an ABAP program with a custom screen

Solution to idea Chinese prism garbled code error -- console Chinese output prism garbled code
随机推荐
Office VR porn, coquettish operation! The father of Microsoft hololens resigns!
Chapter I linear table
面试:什么是浅拷贝、深拷贝?
acwing 2816. 判断子序列
C regular expression
acwing 801. 二进制中1的个数(位运算)
Interview: hashcode() and equals()
D structure as index of multidimensional array
面试:hashCode()和equals()
[browser principle] variable promotion
Multimix:从医学图像中进行的少量监督,可解释的多任务学习
Interview: why do integer wrapper classes try to use equals() to compare sizes
Global and Chinese markets of bioreactors 2022-2028: Research Report on technology, participants, trends, market size and share
5-5配置Mysql复制 基于日志点的复制
With a lamp inserted in the nostril, the IQ has risen and become popular in Silicon Valley. 30000 yuan is enough
面试:了解装箱和拆箱操作吗?
Statistical machine learning code set
大规模实时分位数计算——Quantile Sketches 简史
小飞页升级变智能修复Bug更快速了
The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.3 open、creat、close、unlink