您的位置:首页 > 其它

HDU 6095 Rikka with Competition

2017-08-08 19:37 387 查看
题目地址

题意:告诉你n个人的能力值,求出最后的赢家会有哪些。他的获胜条件要不是赢得那方的能力值减去输的那方的能力值,或者随机赢

思路:排序,从大到小去找,知道有一个是一定赢得为止,遍历过的数就是最后的可能的赢家数量

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define N 100010
#define LL __int64
#define lson l,mid,ans<<1
#define rson mid+1,r,ans<<1|1
#define getMid (l+r)>>1
#define movel ans<<1
#define mover ans<<1|1
using namespace std;
const LL mod = 1e9 + 7;
const double eps = 1e-9;
const int inf = 1 << 28;
LL num
;
int main() {
cin.sync_with_stdio(false);
int T;
int n, m;
cin >> T;
while (T--) {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> num[i];
}
sort(num, num + n);
int ans = 1;
for (int i = n - 2; i >= 0; i--) {
if (num[i + 1] - num[i] > m) {
break;
}
ans++;
}
cout << ans << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: