跳到正文

LXR909

813784

再问删除

在洛谷打开
资料、奖项与版本

资料

编号
813784
抓取

版本

  1. v2当前
  2. v1
未完工代码
C++
//CF1134F
#include <bits/stdc++.h>
using namespace std;

int main() {
    // 优化输入输出效率
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    if (!(cin >> t)) return 0;

    while (t--) {
        int n;
        cin >> n;

        vector<int> b(n + 1);
        vector<int> p(n + 1, -1); // p[i] 表示位置 i 放置的数字
        bool valid = true;

        for (int x = 1; x <= n; x++) {
            cin >> b[x];
            
            // 计算数字 x 应该在的位置
            int pos = x - b[x];
            
            // 检查位置是否合法
            if (pos < 1 || pos > n) {
                valid = false;
                continue; // 继续读取剩余的输入,避免输入流混乱
            }
            
            // 检查该位置是否已经被占据
            if (p[pos] != -1) {
                valid = false;
            } else {
                p[pos] = x;
            }
        }

        if (!valid) {
            cout << -1 << '\n';
        } else {
            for (int i = 1; i <= n; i++) {
                cout << p[i] << " \n"[i == n];
            }
        }
    }

    return 0;
}
//C
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

void solve() {
    int n;
    if (!(cin >> n)) return;
    vector<int> h(n);
    map<int, int> counts;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        counts[h[i]]++;
    }
    vector<int> left_books;
    vector<int> right_books;
    vector<int> mid_books;
    for (auto& [height, cnt] : counts) {
        if (cnt >= 2) {
            left_books.push_back(height);
            right_books.push_back(height);
            cnt -= 2;
        } else {
            right_books.push_back(height);
            cnt -= 1;
        }
        for (int k = 0; k < cnt; ++k) {
            mid_books.push_back(height);
        }
    }
    sort(left_books.begin(), left_books.end());
    sort(right_books.begin(), right_books.end(), greater<int>());
    int k = left_books.size() + right_books.size();
    cout << k << endl;
    bool first = true;
    for (int x : left_books) {
        if (!first) cout << " ";
        cout << x;
        first = false;
    }
    for (int x : mid_books) {
        if (!first) cout << " ";
        cout << x;
        first = false;
    }
    for (int x : right_books) {
        if (!first) cout << " ";
        cout << x;
        first = false;
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    if (cin >> t) {
        while (t--) {
            solve();
        }
    }
    return 0;
}
//E
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    if (!(cin >> t)) return 0;

    while (t--) {
        int n, k;
        cin >> n >> k;

        int xor_sum = 0;
        for (int i = 1; i <= n; i++) {
            int a;
            cin >> a;
            
            // 核心逻辑:只有当 (n-i) % (k+1) != 0 时,该堆的石子才参与异或
            if ((n - i) % (k + 1) != 0) {
                xor_sum ^= a;
            }
        }

        // 异或和不为 0,Alice 胜;否则 Bob 胜
        if (xor_sum != 0) {
            cout << "Alice\n";
        } else {
            cout << "Bob\n";
        }
    }

    return 0;
}

我是LXR

还没有收录这位用户的文章。