upc组队赛16 Melody【签到水】

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
",x)
#define pri2(x,y) printf("%d %d
",x,y)
#define pri3(x,y,z) printf("%d %d %d
",x,y,z)
#define prl(x) printf("%lld
",x)
#define prl2(x,y) printf("%lld %lld
",x,y)
#define prl3(x,y,z) printf("%lld %lld %lld
",x,y,z)
#define ll long long
#define LL long long
inline ll read(){ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';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=2000005;
ll a[maxn];
ll b[maxn];
int main()
{
  int n;
  sca(n);
  rep(i,0,n)
    scl(a[i]);
  rep(i,0,n)
    scl(b[i]);
  ll k = 0;
  rep(i,1,n)
  {
    if((LL)(a[i]-a[i-1])*(LL)(b[i]-b[i-1]) > 0)
      continue;
    else
      k++;
  }
  prl(k+1);
}
 
原文地址:https://www.cnblogs.com/llke/p/10809727.html