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 ...
随机推荐
- Lambda表达式where过滤数据
使用Lambda的表达式来过滤符合条件的数据.下面的代码实现,是把字符阵列中,把名字长度等于3元素找出来. class Bv { public void LambdaExpression() { st ...
- Hibernate入门1 - Hibernate概述及第一个小例子
一.什么是ORM? ORM,即Object Relational Mapping.我们知道,利用面向对象的思想编写的数据库应用程序最终都是把对象信息保存在关系型数据库中,于是需要编写与底层数据库相关的 ...
- react写一个todo
概述 最近学习redux,打算先复习一下react,所以用react写了一个todo.记录下来,供以后开发时参考,相信对其他人也有用. 代码 代码请见我的github 组织架构如下图:
- springboot知识点补充(一)
测试配置 @RunWith(SpringRunner.class) @SpringBootTest @Configuration @ActiveProfiles("test") p ...
- u-boot中debug的一些总结
研究u-boot,首要搞清楚的是代码的流程,运行流程是什么样子的呢?不知道,就看log.这就要把log信息 打开.研究u-boot的文件,发现里面是很多DEBUG宏定义的打印,这个打印着怎么打开呢? ...
- C语言中const关键字的用法
关键字const用来定义常量,如果一个变量被const修饰,那么它的值就不能再被改变,我想一定有人有这样的疑问,C语言中不是有#define吗,干嘛还要用const呢,我想事物的存在一定有它自己的道理 ...
- IDEA的maven配置
刚接触maven的时候,也知道maven目录下有个setting文件可以设置远程maven库的地址,但自己实践的时候,发现setting文件的地址都被注释掉了,但是jar包还是能成功下载下来,那这个下 ...
- getResourceAsStream的3种路径配置
getResourceAsStream有以下几种: 1. Class.getResourceAsStream(String path) : path 不以’/'开头时默认是从此类所在的包下取资源,以’ ...
- Python基础教程(第3版) 笔记(二)
1.8模块Python提供了完成(某人的年 龄为32.9,并想将这个值向下圆整为32,因为他还没有满33岁)这种任务的函 数floor.导入模块,可以使用特殊命令import.函数floor包含在模块 ...
- JAVA中的COPYONWRITE容器
Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容,当某个人想要修改这个内容的时候,才会真正把内容Copy出去形成一个新的内容然后再改, ...