题解:P14358 [CSP-J 2025] 座位 / seat(民间数据)

· · 题解

P14358 [CSP-J 2025] 座位 / seat

2025 CSP-J/S rp++!

solution

其实就是看样例分析,得出公式。

设小 R 的成绩在考场的座位为第 r 行第 c 列,小 R 的成绩在排序后的成绩序列中排名第 i 个。

根据分析可以得到:

:::warning[小坑点] 输出是先列后行。 ::::

AC code

#include <bits/stdc++.h>
#define int long long
#define maxn 100010
#define endl '\n'
using namespace std;

int n, m, r, c, mark, point, a[maxn];
void solve() {
    point = 1;
    for (int i = 2; i <= n * m; i++) {
        if (a[i] > mark) {
            point++;
        }
    }
    c = (point - 1) / n + 1;
    if (c % 2 == 0) {
        if (point % n == 0) {
            r = 1;
        }
        else {
            r = n - point % n + 1;
        }
    }
    else {
        if (point % n == 0) {
            r = n;
        }
        else {
            r = point % n;
        }
    }
    cout << c << " " << r << endl;
}
signed main() {
    cin >> n >> m;
    for (int i = 1; i <= n * m; i++) {
        cin >> a[i];
    }
    mark = a[1];
    solve();
    return 0;
}

其它

祝所有选手都能 AK CSP,取得圆满的成绩!求管理通过!