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