HDU6095
Rikka with Competition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 772 Accepted Submission(s): 588
Problem Description
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
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
Sample Input
5 3
1 5 9 6 3
5 2
1 5 9 6 3
Sample Output
1
Source
//2017-09-22
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; int n, arr[N], k; int main()
{
int T;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &k);
for(int i = ; i < n; i++){
scanf("%d", &arr[i]);
}
sort(arr, arr+n);
int ptr = n-, ans = ;
while(ptr >= && arr[ptr]-arr[ptr-] <= k){
ptr--;
ans++;
}
printf("%d\n", ans+);
} return ;
}
HDU6095的更多相关文章
- 2017 Multi-University Training Contest - Team 5——HDU6095&&HDU6090&&HDU
HDU6095——Rikka with Competition 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6095 题目意思:抱歉虽然是签到题,现场 ...
- 【多校联合】(HDU6095)Rikka with Competition
题意:给定$n$个数,代表$n$个选手的能量高低,现在再给一个$k$,任意在$n$个选手中挑取两个选手比赛,如果$|a_i−a_j|>K$,那么能量高的选手获胜,另一个将被淘汰,否则两个人都有机 ...
- 2017多校Round5(hdu6085~hdu6095)
补题进度:7/11 1001(模意义下的卷积) 题意: 给出长度<=50000的两个数组A[] B[],保证数组中的值<=50000且A[]中数字两两不同,B[]中数字两两不同 有5000 ...
随机推荐
- Pycharm2018的激活方法或破解方法
1.授权服务器激活 优点:方便快捷 缺点:激活的人数多了就容易被封杀,所以可能经常需要去激活 选择License server激活,然后填入: idea.qmanga.com或http://xidea ...
- 设置UniDbGrid的整行显示颜色,如果某字段值是我们的控制字段
设置UniDbGrid的整行显示颜色,如果某字段值是我们的控制字段,使用下列判断设置更快捷一点: procedure TUniForm.UniDBGridDrawColumnCell(Sender: ...
- Interview Common Sample Codes
1. Quick Sort: int partition(int A[], int p, int r) { int x = A[r]; // Pivot element int i = p - 1; ...
- while循环 格式化输出 密码本 编码的初识
第二天课程整理 while 循环 why : while ' 循环' 的意思 what : while 无限循环 how : 1.基本结构 while + 条件 循环的代码 初识循环 while tr ...
- Python 有序字典(OrderedDict)与 普通字典(dict)
Python 的基础数据类型中的字典类型分为:无序字典 与 有序字典 两种类型 1.无序字典(普通字典): my_dict = dict()my_dict["name"] = &q ...
- 通俗理解N-gram语言模型。(转)
从NLP的最基础开始吧..不过自己看到这里,还没做总结,这里有一篇很不错的解析,可以分享一下. N-gram语言模型 考虑一个语音识别系统,假设用户说了这么一句话:“I have a gun”,因为发 ...
- 十进制转化为二进制Java实现
提取2的幂 这个方法用代码实现貌似有点麻烦,需要探测大小,我只实现了整数十进制到二进制的转化 /* * 提取2的幂 */ public static String TenToBin1(int ten) ...
- 火狐浏览器安装 Modify Headers 插件
一.火狐浏览器插件安装 这里以火狐浏览器的Modify Headers插件安装为例,展示火狐插件的安装: 1.打开火狐浏览器,右上角选择“附加组件” 2.搜索Modify Headers插件 3.安装 ...
- django rest framework mixins小结
本篇对drf中的mixins进行简要的分析总结. from rest_framework import viewsets 在这个viewsets中,只有5类Minxin,他们与http方法对应如下: ...
- 3-5 Vue中的样式绑定
Vue中的样式绑定: 本案例,简单设计一个<div>的点击绑定事件来改变div的样式效果 方法一:[class] ①(class和对象的绑定) //如上,运用class和一个对象的形式来解 ...