题解:P11538 [Code+#5] chess
题目传送门
\texttt{Solution}
一道水题,按照题意模拟即可。注意在每一次的移动之后,有两项操作:
-
- 标记数组要把原来的位置改为
0 ,移动后的位置改为1 。
还有,error! 后面有感叹号,一定不要漏掉,否则你会喜提
\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;
}
完结,这题真简单。