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;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define scac(x) scanf("%c",&x)
#define sca(x) scanf("%d",&x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pri(x) printf("%d\n",x)
#define pri2(x,y) printf("%d %d\n",x,y)
#define pri3(x,y,z) printf("%d %d %d\n",x,y,z)
#define prl(x) printf("%lld\n",x)
#define prl2(x,y) printf("%lld %lld\n",x,y)
#define prl3(x,y,z) printf("%lld %lld %lld\n",x,y,z)
#define ll long long
#define LL long long
inline ll read(){ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;}
#define read read()
#define pb push_back
#define mp make_pair
#define P pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define MOD 998244353
#define mod 1e9+7
#define N 1000005
const int maxn=;
ll a[maxn];
ll b[maxn];
int main()
{
int n;
sca(n);
rep(i,,n)
scl(a[i]);
rep(i,,n)
scl(b[i]);
ll k = ;
rep(i,,n)
{
if((LL)(a[i]-a[i-])*(LL)(b[i]-b[i-]) > )
continue;
else
k++;
}
prl(k+);
}
												

最新文章

  1. 最新IP地址数据库Dat格式-高性能高并发版(2017年1月)
  2. DIJ产品系列
  3. 20145234黄斐《信息安全系统设计基础》GDB调试汇编堆栈过程分析
  4. servlet的转发与重定向
  5. C语言-删除重复字符
  6. windows下的BT服务器搭建方案
  7. Spring对Hibernate事务管理【转】
  8. 关于springmvc 方法注解拦截器的解决方案,多用于方法的鉴权
  9. js导出execl兼容ie Chrome Firefox各种主流浏览器(js export execl)
  10. 【Android Developers Training】 106. 创建并检测地理围栏
  11. js版贪吃蛇
  12. 【转】Cisco交换机策略路由
  13. 解决 Excel2013打开提示 文件格式和扩展名不匹配。文件可能已损坏或不安全
  14. twisted reactor执行流程
  15. 使用Homebrew安装Git与Github在idea中的配置
  16. mybatis框架入门程序:演示通过mybatis实现数据库的添加操作
  17. VMware workstation 语言包切换
  18. #leetcode刷题之路31-下一个排列
  19. http 服务器编程 适配器
  20. DATASNAP数据提交之FIREDAC的TFDJSONDeltas

热门文章

  1. BZOJ 1109 (LIS)
  2. python开发之路-day02
  3. python学习第十五天字典的创建及增删改查操作方法
  4. JS方法使用中文出参数 ,报错异常
  5. Saying goodbye to Flash in Chrome一代人的回忆FLASH
  6. Gradle中的GroupID和ArtifactID指的是什么?
  7. JS高级 — 函数中的this指向问题
  8. Redis在windows下的环境搭建
  9. shell判断用户是否已经在系统中登录
  10. java解析xml(使用jdom解析xml)