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 ...
随机推荐
- <Listener>HttpSessionListener和HttpSessionAttributeListener区别
一.HttpSessionListener HttpSessionListener是对Session的一个监听,主要监听关于Session的两个事件,即初始化和销毁.HttpSessionListen ...
- 【算法】实现字典API:有序数组和无序链表
参考资料 <算法(java)> — — Robert Sedgewick, Kevin Wayne <数据结构> ...
- 程序猿的日常——工作中常用的Shell脚本
工作当中总是会有很多常用的linux或者命令,这里就做一个总结 文件远程拷贝 如果想把文件从本机拷贝到远程,或者从远程下载文件到本地. # 把本地的jar拷贝到远程机器xxxip的/home/sour ...
- 开发微信小程序——古龙小说阅读器
概述 由于面试的关系接触了一下微信小程序,花了2晚上开发了一个带书签功能的古龙小说阅读器,并且已经提交审核等待发布.这篇博文记录了我的开发过程和对微信小程序的看法,供以后开发时参考,相信对其他人也有用 ...
- Kubernetes-1
master 节点负责管理整个集群,管理的控制面板,全局的角色和调度 3个组件 API Server : 统一入口 kubectl 客户端管理工具 Etcd 数据库 Scheduler 集群的调度 C ...
- RSA实现JS前端加密,PHP后端解密
web前端,用户注册与登录,不能直接以明文形式提交用户密码,容易被截获,这时就引入RSA. 前端加密 需引入4个JS扩展文件,jsbn.js.prng4.js.rng.js和rsa.js. <h ...
- Maven - Tips
1- Maven的Settings http://maven.apache.org/settings.html 2- Maven设置代理 示例: <proxies> <proxy&g ...
- [EXP]Microsoft Windows 10 - XmlDocument Insecure Sharing Privilege Escalation
Windows: XmlDocument Insecure Sharing Elevation of Privilege Platform: Windows (almost certainly ear ...
- linux中变量的一些操作方法
常见的一般有如下操作,可以对字符串进行简单操作: echo ${#var}打印变量var长度 echo "$var:3:8" 打印变量var第4个字符开始的8个字符echo ${v ...
- C# Winform同时启动多个窗体类
首先创建一个类,存放将要同时显示的窗体 using System; using System.Collections.Generic; using System.Linq; using System. ...