题目描述
YellowStar is versatile. One day he writes a melody A = [A1, ..., AN ], and he has a standard melody B = [B1, ..., BN ]. YellowStar can split melody into several parts, it can be expressed as: K split position S = [S1, ..., SK], satisfy 1 ≤ S1 < S2 < · · · < SK = N. Melody A and B will be split into K parts:
Two parts of melody are equal while the change of tone is consistent. It can be expressed as:
A = [A1, ..., AM ] equal to B = [B1, ..., BM ] need to satisfy:
Now YellowStar wants each part of his melody A equals to each part of standard melody B. In other words, the following conditions need to be met:
YellowStar also wants the number K of split parts as minimum as possible.
输入
Input is given from Standard Input in the following format:
N
A1 A2 . . . AN
B1 B2 . . . BN
Constraints
1 ≤ N ≤ 105
1 ≤ Ai, Bi ≤ 109
All Ai are distinct and all Bi are distinct.
All inputs are integers.
输出
Print one line denotes the minimal integer K .
样例输入
复制样例数据
5 1 3 2 4 5 4 9 10 11 8
样例输出
3
水题一道,只要注意
这个就行了,接下来上代码吧(题意可以谷歌翻译,毕竟我的英文水平也不高= =)
#include<bits/stdc++.h>
using namespace std;
int a[100009],b[100009];
int main()
{
int n;
cin >> n;
for(int i=0;i<n;i++){
cin >> a[i];
}
for(int i=0;i<n;i++){
cin >> b[i];
}
int sum=1;//例如分两段,就有三部分,所以是从一开始
for(int i=1;i<n;i++){
if((a[i-1]<a[i]&&b[i-1]<b[i])||(a[i-1]>a[i]&&b[i-1]>b[i]))//就是题目所给的条件
continue;//符合就跳过
else
sum++;
}
cout << sum;
}
因为是英文队友说的迷迷糊糊的愣是写了1个小时= =,也是惊了,(哎,还是吃了没文化的亏啊QWQ)论学好英文的重要性。