题解:P11538 [Code+#5] chess

· · 题解

题目传送门

\texttt{Solution}

一道水题,按照题意模拟即可。注意在每一次的移动之后,有两项操作:

还有,error! 后面有感叹号,一定不要漏掉,否则你会喜提 0 分大礼包一份。

\texttt{Code}

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int maxn = 1e3 + 5;
int n, m, k, a[maxn];
bool vis[maxn];

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin >> n >> m >> k;

    for (int i = 1; i <= m; i++) {
        cin >> a[i];
        vis[a[i]] = true;
    }

    while (k--) {
        int x; cin >> x;
        int num = a[x];
        bool flag = false;

        for (int i = 1; i <= n - num; i++) {
            if (vis[num + i] == false) {
                a[x] += i;
                cout << a[x] << "\n";
                vis[num] = false;
                vis[num + i] = true;
                flag = true;
                break;
            }
        }

        if (!flag) cout << "error!\n";
    }

    return 0;
}

完结,这题真简单。