Melody

题目描述

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)论学好英文的重要性。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值