跳到正文

题解

题解:P8467 [Aya Round 1 B] 甲(one)

#SUSPENDED#约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月26日
篇幅
约 3 分钟
题目
P8467

版本

  1. v1当前

P8467 题解

思路

通过我的观察题目的意思就是让我们满足条件的 PP 使得:

aP1−1=aP2=aP3+1a_{P_1}-1=a_{P_2}=a_{P_3}+1

aP4=aP5a_{P_4}=a_{P_5}

然后再枚举 a5a_5:对于每组给定的 a1,a2,a3,a4a_1,a_2,a_3,a_4,枚举 a5a_5 的可能取值(00 到 99),并检查是否存在满足条件的排列 PP。

排列检查:对于每个可能的 a5a_5,检查是否存在满足条件的排列 PP。

AC 代码

C++
#include <bits/stdc++.h>
using namespace std;
bool kkksc03(int a[5]) {
    int temp[5];
    for (int i = 0; i < 5; i++) temp[i] = a[i];
    sort(temp, temp + 5);
    do {
        if (temp[0] - 1 == temp[1] && temp[1] == temp[2] + 1 && temp[3] == temp[4]) return true;
        int k = -1;
        for (int i = 4; i > 0; --i) {
            if (temp[i - 1] < temp[i]) {
                k = i - 1;
                break;
            }
        }
        if (k == -1) break;
        int l = -1;
        for (int i = 4; i > k; i--) {
            if (temp[i] > temp[k]) {
                l = i;
                break;
            }
        }
        swap(temp[k], temp[l]);
        reverse(temp + k + 1, temp + 5);
    } while (1);
    return 0;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int a[5];
        for (int i = 0; i < 4; i++) cin >> a[i];
        bool found = 0;
        for (int a5 = 0; a5 <= 9; a5++) {
            a[4] = a5;
            if (kkksc03(a)) {
                found = true;
                break;
            }
        }
        cout << (found ? 1 : 0) << '\n';
    }
    return 0;
}
原文