Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

A wrestling match will be held tomorrow. n players will take part in it. The ith player’s strength point is ai.

If there is a match between the ith player plays and the jth player, the result will be related to |ai−aj|. If |ai−aj|>K, the player with the higher strength point will win. Otherwise each player will have a chance to win.

The competition rules is a little strange. Each time, the referee will choose two players from all remaining players randomly and hold a match between them. The loser will be be eliminated. After n−1 matches, the last player will be the winner.

Now, Yuta shows the numbers n,K and the array a and he wants to know how many players have a chance to win the competition.

It is too difficult for Rikka. Can you help her?

 
Input
The first line contains a number t(1≤t≤100), the number of the testcases. And there are no more than 2 testcases with n>1000.

For each testcase, the first line contains two numbers n,K(1≤n≤105,0≤K<109).

The second line contains n numbers ai(1≤ai≤109).

 
Output
For each testcase, print a single line with a single number -- the answer.
 
Sample Input
2
5 3
1 5 9 6 3
5 2
1 5 9 6 3
 
Sample Output
5
1
 
如果差距在k及以内,两者都有赢的可能。如果差距大于k,大者赢。
因此找出两两差距都在k以内的大数有几个即可。
 
 #include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<vector>
using namespace std; int a[];
bool cmp(int x,int y)
{
return x>y;
} int main()
{
int T,n,k;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n,cmp);
int i;
for(i=;i<n-;i++)
{
if(a[i]-a[i+]>k)
break;
}
printf("%d\n",i+);
}
return ;
}
 
 

HDU 6095 17多校5 Rikka with Competition(思维简单题)的更多相关文章

  1. HDU 6106 17多校6 Classes(容斥简单题)

    Problem Description The school set up three elective courses, assuming that these courses are A, B, ...

  2. HDU 6092 17多校5 Rikka with Subset(dp+思维)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  3. HDU 6090 17多校5 Rikka with Graph(思维简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  4. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  5. HDU 6034 17多校1 Balala Power!(思维 排序)

    Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...

  6. HDU 6077 17多校4 Time To Get Up 水题

    Problem Description Little Q's clock is alarming! It's time to get up now! However, after reading th ...

  7. HDU 6143 17多校8 Killer Names(组合数学)

    题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...

  8. HDU 6045 17多校2 Is Derek lying?

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others)    Memory ...

  9. HDU 6124 17多校7 Euler theorem(简单思维题)

    Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...

随机推荐

  1. 牛客练习赛32-D-MST+tarjin割边

    链接:https://ac.nowcoder.com/acm/contest/272/D来源:牛客网 题目描述 小p和他的朋友约定好去游乐场游玩,但是他们到了游乐场后却互相找不到对方了. 游乐场可以看 ...

  2. P2756 飞行员配对方案问题

    题目背景 第二次世界大战时期.. 题目描述 英国皇家空军从沦陷国征募了大量外籍飞行员.由皇家空军派出的每一架飞机都需要配备在航行技能和语言上能互相配合的2 名飞行员,其中1 名是英国飞行员,另1名是外 ...

  3. 函数使用二:采购申请BAPI_PR_CREATE

    REPORT YTEST01. ***************************采购申请创建*****************************begin DATA:LV_BANFN TY ...

  4. git相关知识(github,idea等的配置)

    本地git提交文件到github上: 1.在github上创建项目 2.使用git clone https://github.com/xxxxxxx/xxxxx.git克隆到本地 3.编辑项目 4.g ...

  5. 【转】JavaScript => TypeScript 入门

    几个月前把 ES6 的特性都过了一遍,收获颇丰.现在继续来看看 TypesScript(下文简称为 “TS”).限于经验,本文一些总结如有不当,欢迎指正. 官网有这样一段描述: TypeScript ...

  6. Talend 从Excel导入Saleforce数据(二) TMAP是精髓

    TMap LookUp 经过测试的结果: ------------------------------------------ LookUp最好从CSV读数据,这样是最快了(20万记录1s).从Sal ...

  7. C++简单输入输出-计算火车运行时间

    //写的很差,无力tc 7-4 计算火车运行时间 (17 分) 本题要求根据火车的出发时间和达到时间,编写程序计算整个旅途所用的时间. 输入格式: 输入在一行中给出2个4位正整数,其间以空格分隔,分别 ...

  8. 尚学堂java 参考答案 第七章

    本答案为本人个人编辑,仅供参考,如果读者发现,请私信本人或在下方评论,提醒本人修改 一.选择题 1.ACD 解析:B:java中左边不能直接直接指定长度,和C语言不一样 2.B 3.C 解析:B各行分 ...

  9. 4.3 if-else语句使用

    Q:对输入的成绩进行登记划分. #include<iostream> #include<cstdio> using namespace std; int main() { in ...

  10. jvm常用参数

    -Xms512m:初始堆内存 -Xmx512m:最大堆内存 -XX:PermSize=256m:初始永久代内存(方法区,非堆) -XX:MaxPermSize=256m:最大永久代内存(方法区,非堆) ...