跳到正文

题解

题解:P13822 「Diligent-OI R2 B」白露为霜

xiaoyouyou66约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月30日
篇幅
约 1 分钟
题目
P13822

版本

  1. v1当前

思路

我们首先判断两个折线序列能否通过有限次修改操作相互转换,关键在于验证它们的奇偶性模式和端点差值是否匹配,根据这个思路,我们可以得出代码。

献上代码

C++
#include <bits/stdc++.h>
using namespace std;
bool solve()
{
    int n;
    cin >> n;
    vector <int> a(n), b(n);
    for(int &x : a) cin >> x;
    for(int &x : b) cin >> x;
    if(n == 1) return true;
    for(int i = 0;i < n - 1;i++)
        if(abs(b[i] - b[i + 1]) != 1)
            return false;
    for(int i = 0;i < n;i++)
        if((a[i] - b[i]) % 2 != 0)
            return false;
    return true;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--) cout << (solve() ? "Yes" : "No") << '\n';
    return 0;
}
原文