1 solutions
-
0
锦标赛
将所有人排序之后,如果两个相邻的人之间的差超过了 ,那么低的人就无法战胜高的人。
所以从大到小,找到第一段差超过 的,那么后面的人没有办法赢。前面的人可以从前往后依次打过去,第二大战胜第一大,第三大战胜第二大,这样下去,都能获胜。
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm> #define ll long long using namespace std; ll a[1000010]; int main() { freopen("tournament.in", "r", stdin); freopen("tournament.out", "w", stdout); ll n, k; int ans = 1; scanf("%lld%lld", &n, &k); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); } sort(a, a + n); for (int i = n - 1; i > 0; i--) { if ((a[i] - a[i - 1]) > k) break; ans++; } printf("%d\n", ans); }
- 1
Information
- ID
- 186
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 9
- Tags
- (None)
- # Submissions
- 7
- Accepted
- 5
- Uploaded By