2017 beijing icpc E - Rikka with Competition
2017-09-22 22:01:19
writer:pprp
A wrestling match will be held tomorrow. nn players will take part in it. The iith player’s strength point is aiai.
If there is a match between the iith player plays and the jjth player, the result will be related to |ai−aj||ai−aj|. If |ai−aj|>K|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−1n−1 matches, the last player will be the winner.
Now, Yuta shows the numbers n,Kn,K and the array aa 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?
InputThe first line contains a number t(1≤t≤100)t(1≤t≤100), the number of the testcases. And there are no more than 22 testcases with n>1000n>1000.
For each testcase, the first line contains two numbers n,K(1≤n≤105,0≤K<109)n,K(1≤n≤105,0≤K<109).
The second line contains nn numbers ai(1≤ai≤109)ai(1≤ai≤109).
OutputFor 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
代码如下:
#include <iostream>
#include <algorithm> using namespace std;
const int maxn = ;
int arr[maxn]; int main()
{
int cas;
cin >> cas;
while(cas--)
{
int n, k;
cin >> n >> k;
int ans = ;
for(int i = ; i < n ; i++)
{
cin >> arr[i];
}
sort(arr,arr+n);
for(int i = n-; i > ; i--)
{
if(arr[i]-arr[i-] > k)
break;
ans++;
}
cout << ans << endl;
} return ;
}
2017 beijing icpc E - Rikka with Competition的更多相关文章
- 2017 beijing icpc A - Euler theorem
2017-09-22 21:59:43 writer:pprp HazelFan is given two positive integers a,ba,b, and he wants to calc ...
- 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- 2017 ACM ICPC Asia Regional - Daejeon
2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...
- 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest
2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...
- 2017 多校5 Rikka with String
2017 多校5 Rikka with String(ac自动机+dp) 题意: Yuta has \(n\) \(01\) strings \(s_i\), and he wants to know ...
- 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- 2017 ACM/ICPC Asia Regional Qingdao Online
Apple Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submi ...
- 记2017青岛ICPC
2017青岛ICPC 11月4日 早上很早到达了青岛,然后去报道,走了好久的校园,穿的很少冷得瑟瑟发抖.中午教练请吃大餐,吃完饭就去热身赛了. 开幕式的时候,教练作为教练代表讲话,感觉周围的队伍看过来 ...
- 记2017沈阳ICPC
2017沈阳ICPC 10月20日 早上十点抵达沈阳,趁着老师还没到,跑去故宫游玩了一下,玩到一点多回到宾馆,顺便吃了群里大佬说很好吃的喜家德虾饺(真的好好吃),回到宾馆后身体有点不舒服了,头晕晕的, ...
随机推荐
- rabbitmq延迟队列相关
https://blog.csdn.net/qq_26656329/article/details/77891793 --------------rabbitmq queue_decla ...
- React中ref的用法
在React数据流中,父子组件唯一的通信方式是通过props属性:那么如果有些场景需要获取某一个真实的DOM元素来交互,这时候就要用到React的refs属性. 1.可以给DOM元素添加ref属性 c ...
- Sublime Text 中文
1.打开Sublime Text 2.Ctrl+Shift+P,输入Package Control: Install Package回车 3.输入LocalizedMenu,回车 4.点击菜单help ...
- 内核通信之Netlink源码分析-用户内核通信原理2
2017-07-05 上文以一个简单的案例描述了通过Netlink进行用户.内核通信的流程,本节针对流程中的各个要点进行深入分析 sock的创建 sock管理结构 sendmsg源码分析 sock的 ...
- SQL事务回滚 写法(转)
以下是SQL 回滚的语句:方案一:SET XACT_ABORT ON--如果产生错误自动回滚GOBEGIN TRANINSERT INTO A VALUES (4)INSE ...
- cmd 运行jar文件
将java工程打成jar包,但第三方jar包并没有包含在包中,当在命令行中运行jar包时,出现类找不到的异常, 在网上看到解决办法是将第三方jar包放到JDK的扩展类文件夹中(%JAVA_HOME%/ ...
- 网页中Cache各字段含义
Pragma 当该字段值为"no-cache"的时候(事实上现在RFC中也仅标明该可选值),会知会客户端不要对该资源读缓存,即每次都得向服务器发一次请求才行. Expires 有了 ...
- map::erase陷阱
map::erase函数在不同版本stl中的差异 1. C++98和C++11标准 http://www.cplusplus.com/reference/map/map/erase/ 2. pj st ...
- python全栈开发从入门到放弃之socket并发编程多进程
1.1 multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程 ...
- vue过滤器和监视器的小例子
过滤器其实就是一个函数,把当前的值传递到函数里面,加工处理后,返回到当前,过滤器使用|(管道符),默认传递参数,如果还要传递参数就要手动传递 过滤器函数总接收表达式的值 (之前的操作链的结果) 作为第 ...