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. POJ-3041-建图/二分图匹配/网络流

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26351   Accepted: 14254 Descr ...

  2. visual studio利用 indent guides 格式化代码 添加竖线

    点击 Visual Studio 2013 工具—扩展和更新—联机 然后输入indent guides 自动搜索出来这个插件(如图).注:Visual Studio 2010需要自己在网上下载安装. ...

  3. springboot自动装配

    Spring Boot自动配置原理 springboot自动装配 springboot配置文件 Spring Boot的出现,得益于“习惯优于配置”的理念,没有繁琐的配置.难以集成的内容(大多数流行第 ...

  4. InnoDB存储引擎的 B+ 树索引

    B+ 树是为磁盘设计的 m 叉平衡查找树,在B+树中,所有的记录都是按照键值的大小,顺序存放在同一层的叶子节点上,各叶子节点组成双链表.叶节点是数据,非叶节点是索引. 首先,需要清楚:B+ 树索引并不 ...

  5. ajax请求成功前,加载中loading显示

    /*第一次刷新--非定时器刷新数据*/ var fistInitColumn = true; var getAllColumnDatas = function(){ var params = {}; ...

  6. OpenJDK换为JDK(CentOS)

    说明:应该来说没必要非把OpenJDK卸载掉,只要让$PATH中我们安装的jdk的目录较OpenJDK所在的/usr/bin先出现就好了:简言之跳过下边的第一步直接从第二步开始更科学一些. 1.卸载O ...

  7. pycharm 配置使用

    1. 如何添加Package File-> Settings -> Project :XXXX -> Project Interpreter 点右边的"+"号,输 ...

  8. python logs

    # -*- coding: utf-8 -*-import loggingimport sysimport osimport xlrdfrom UtilAzxu import Properties# ...

  9. react router @4 和 vue路由 详解(五)react怎么通过路由传参

    完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 7.react怎么通过路由传参? a.通配符传参(刷新页面数据不丢失) //在定义路由的 ...

  10. Win10系列:VC++绘制几何图形5

    打开D2DBasicAnimation.h头文件,并在D2DBasicAnimation类中添加如下的代码: private:     //声明成员变量point     D2D1_POINT_2F ...