Files
python/TangDou/AcWing/BIT/244_BF.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
894 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
// 通过了 7/10个数据
const int N = 1e5 + 10;
int h[N];
int st[N];
int ans[N];
int n;
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; i++) scanf("%d", &h[i]);
// 第一个放过,不讨论,输进来也是0,不输也是0
for (int i = n; i; i--) { // 从后向前枚举每头牛
int cnt = 0;
for (int j = 1; j <= n; j++) {
if (!st[j]) cnt++; // 如果此位置没有被占用,是可以用的
if (cnt == h[i] + 1) { // 寻找第h[i]+1个未被占据的位置
st[j] = 1; // 标识此位置被某个奶牛占据过了
ans[i] = j; // 记录i号奶牛占据的是j号位置
break;
}
}
}
for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
return 0;
}