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 ...
随机推荐
- [au3]批量输入号码程序
批量输入号码程序 这个文件可以随时产生一个剪贴板文字的文本文件,以供其他程序读取. 这个程序修改了许多次了,主要是针对网络延迟的问题. 最终找到了解决方案:探测输入的界面的反馈信息,也就是反馈的颜色. ...
- 为什么需要micro-service构建平台
最近一直在做micro-service的开发平台建设.由于这是一个实验项目,目前所有工作都得靠自己操刀. 今天在总结用python开发一个web service时,偶有所得,这让我建设micro-se ...
- 13.翻译系列:Code-First方式配置多对多关系【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/configure-many-to-many-relationship-in-code- ...
- 准备情人节礼物比写代码难?来看看IT直男给女友们的礼物
今天是情人节,据说IT直男在每个这样弥漫着恋爱气息的日子里都能把礼物送成"辣眼睛"现场,为了反(zheng)驳(shi)这个观点,小编特意走访了网易云的架构师.工程师.产品经理.程 ...
- Java诊断工具
官方文档:Arthas(阿尔萨斯) 1. 安装成功后通过 arthas 命令使用 arthas软件 进入后显示服务器正在运行的Java进程: 2. help显示 atrhas 的功能列表
- Egg中使用egg-mongoose和常用的Mongoose 方法
Mongoose Mongoose就是一套操作MongoDB数据库的接口,而Egg中有对应的插件egg-mongoose. 安装 $ npm install egg-mongoose --save 配 ...
- python numpy安装
一.python下的numpy安装方法 第一步:安装python,这里不做介绍. 第二步:打开cmd看python是否安装成功. 第三步:输入 python -m pip install -U pip ...
- Xamarin.Android 使用 Encoding.GetEncoding("GB2312") 报错解决方案
问题描述:使用byte转换成汉字编码格式,debug模式下可以正常运行,但是release模式下就会出现死机问题. 排除过程:最开始不知道是编码格式转换错误,于是把相关代码块注释掉,然后进行relea ...
- Android Systom
- 常用的npm指令总结
一.安装指令,通常是全局安装 npm install <package name> -g 二.移除全局安装包 npm uninstall <package name> -g 三 ...