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. gleez框架获得时间控件

    1,首先你要在你的页面上引用一个js <script src="<?php echo URL::base() ?>media/vendor/datepicker/Wdate ...

  2. python 绝版线程池

    2.绝版线程池设计思路:运用队列queue a.队列里面放任务 b.线程一次次去取任务,线程一空闲就去取任务 import queueimport threadingimport contextlib ...

  3. Div和Span

    Div ——层级元素,这一行不允许有其他元素(用来布局) Span ——用来修饰文本

  4. JTA 使用 MySQL 分布式事务

    假定在MySQL实例1上有表 create table person( id int, name ) ) MySQL实例2上也有一张同样的表,现在从实例1中的 person 表中删除一条数据,并把这条 ...

  5. js 获取数组重复的元素

    //获取数组重复的元素 function refrain(arr) { var tmp = []; if(Array.isArray(arr)) { arr.concat().sort().sort( ...

  6. free结果解释

    free用于查询内存使用情况,不过其多个数值经常让人感到迷惑,下边对其结果各值进行解释. Mem 1862--总内存/1770--已使用内存/92--未使用内存/199--输出缓存/637--输入缓存 ...

  7. ID基本操作(创建主页,复制主页,把主页应用到多个页面)5.11

    主页上的对象将会显示在应用在这个主页上的所有页面. 一.创建主页的方法: 1.页面面板,右上方点击,可以新建主页..前缀:用来识别页面面板中的各个页面所应用的主页.最多可输入四个字符.名称:输入主页跨 ...

  8. 输出链表的倒数第K个值

    题目描述 输入一个链表,输出该链表中倒数第k个结点.   思路一:链表不能向前遍历,只能向后遍历.因此倒数第K个结点就是 正序的  :len(链表)-1-K的下一个.  注意,此处的思路与代码中具体实 ...

  9. SpringBoot + Security实现权限控制

    网上找了好几个,因为各种原因不太行,下面这个亲测可行 参考:https://blog.csdn.net/u012702547/article/details/54319508 基于SpringBoot ...

  10. 《Python》网络编程基础

    计算机网络的发展及基础网络概念 问题:网络到底是什么?计算机之间是如何通信的? 早期 : 联机 以太网 : 局域网与交换机 广播 主机之间“一对所有”的通讯模式,网络对其中每一台主机发出的信号都进行无 ...