题目中有重复的,所以重复的部分去掉
思路:每两头牛可以互相看见意味着中间的牛身高--
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int maxn = 5055; int n, p, h, m; int a[maxn]; set<pair<int, int>> q; // 判重复 int main() { cin >> n >> p >> h >> m; a[p] = h; for (int i = 1; i <= n; i++) a[i] = h; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; if (q.find(make_pair(x, y)) == q.end()) // 不重复 { for (int j = min(x, y) + 1; j <= max(x, y) - 1; j++) { a[j]--; } q.insert(make_pair(x, y)); } } for (int i = 1; i <= n; i++) cout << a[i] << endl; }