洛谷 P13822
前言:
比第一题好想、简单多了,我就是先开这题,再做第一题的。
题目大意:
定义一个序列为折线,当且仅当 。给定两个折线数组 与 。求 数组是否可以通过若干次变换变成 。
解题思路:
我的思路是通过奇偶性判断。比如:当前的 是奇数,则 一定是偶数,如果要变换的 也恰好是奇数,则无论如何,都可以使 和 相差一,否则变换后,要么相差 ,要么相差 的正整数倍,不满足要求。注意,当 时,要特判。
AC 代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6+20;
int t;
int a[N], b[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
if (n == 1) {
cout << "Yes" << endl;
continue;
}
bool ok = false;
for (int i = 1; i <= n; i++) {
if (a[i] % 2 != b[i] % 2) {
ok = true;
break;
}
}
if (ok) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
}
return 0;
}