问题 F: Melody
时间限制: 1 Sec 内存限制: 128 MB
提交: 394 解决: 133
[提交] [状态] [命题人:admin]
题目描述
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<iostream>
#include<algorithm>
#include<cstring>
const int maxn = 1e5+2;
using namespace std;
int main()
{
int n;
cin>>n;
int a[maxn];
int b[maxn];
for(int i = 0;i<n;i++)cin>>a[i];
for(int i = 0;i<n;i++)cin>>b[i];
int res = 0;
for(int i = 0;i<n;i++){
if((a[i] >a[i-1]&&b[i]<b[i-1])||(a[i]<a[i-1]&&b[i]>b[i-1]))
res++;
}
cout<<res+1<<endl;
}
解析:从1到n找出旋律不同的,分割块数加一,输出即可
问题 J: WTMGB
时间限制: 1 Sec 内存限制: 128 MB
提交: 305 解决: 136
[提交] [状态] [命题人:admin]
题目描述
YellowStar is very happy that the FZU Code Carnival is about to begin except that he has to prepare problems for it. Because the statement of each problem is written in English!
YellowStar types the statements slowly witb high error rate. You must notice that the previous word ’witb’ is wrong(the correct word is ’with’). But YellowStar feels too tired, so he thinks a word is the same as another word if the character at each position of the word is adjacent to the corresponding character of the other word on the keyboard. The keyboard is shown in the figure below:
When two characters on ther keyboard have intersections, they are considered to be adjacent. For example,’S’ is adjacent to ’W’,’E’,’A’,’D’,’Z’ and ’X’.
Now YellowStar asks you to write a program to check whether two strings are the same. Print ’Yes’ if they are the same, and ’No’ otherwise(without the quotes).
输入
Input is given from Standard Input in the following format:
S1
S2
Constraints
1 ≤ | S1 | = | S2 | ≤ 103
S1 and S2 consist only of upper-case English letters.
输出
Print one line denotes the answer.
样例输入
复制样例数据
S U
样例输出
No
分析:直接暴力,找相邻的字符