HDU 6095 17多校5 Rikka with Competition(思维简单题)
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?
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).
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<vector>
using namespace std; int a[];
bool cmp(int x,int y)
{
return x>y;
} int main()
{
int T,n,k;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n,cmp);
int i;
for(i=;i<n-;i++)
{
if(a[i]-a[i+]>k)
break;
}
printf("%d\n",i+);
}
return ;
}
HDU 6095 17多校5 Rikka with Competition(思维简单题)的更多相关文章
- HDU 6106 17多校6 Classes(容斥简单题)
Problem Description The school set up three elective courses, assuming that these courses are A, B, ...
- HDU 6092 17多校5 Rikka with Subset(dp+思维)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- HDU 6090 17多校5 Rikka with Graph(思维简单题)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- HDU 6034 17多校1 Balala Power!(思维 排序)
Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...
- HDU 6077 17多校4 Time To Get Up 水题
Problem Description Little Q's clock is alarming! It's time to get up now! However, after reading th ...
- HDU 6143 17多校8 Killer Names(组合数学)
题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
- HDU 6124 17多校7 Euler theorem(简单思维题)
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...
随机推荐
- python-day73--django课上项目01
from django.db import models # Create your models here. class Book(models.Model): name=models.CharFi ...
- WDA基础四:Select-option的使用
select option是方便用户和数据处理的,就是丑了点... 前面使用的input直接做查询条件有哥弊端,就是查询的时候需要判断字段是否有选择条件,然后要将选择条件做成range table.. ...
- ORACLE SQL 函数 INITCAP()
INITCAP() 假设c1为一字符串.函数INITCAP()是将每个单词的第一个字母大写,其它字母变为小写返回. 单词由空格,控制字符,标点符号等非字母符号限制. select initcap('h ...
- POJ - 题解sol[暂停更新]
初期:一.基本算法: (1)枚举. (poj1753,poj2965) poj1753 话说我用高斯消元过了这题... poj2965 巧了,用高斯消元01矩阵更快(l o l). (2)贪心(poj ...
- 一、持久层框架(Hibernate)
一.Hibernate 使用JDBC做数据库相关功能开发会做很多重复性的工作,创建连接,关闭连接,把字段逐一映射到属性中等.Hibernate把这些进行封装起来,使得数据库访问变得轻松简单. 1.创建 ...
- Git clone 常见用法
二 克隆Git仓库 1.1 从远程仓库中克隆整个代码仓库 mkdir Demo //在当前路径下新建一个文件夹,用来存放将要拉取的整个代码库 cd Demo //进入这个文 ...
- 【转】MVC5学习笔记 BindAttribute
// POST: Movies/Create // 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关 // 详细信息,请参阅 http://go.microsoft.com/fwlink/?L ...
- UNIX-like系统资源检查命令
系统资源主要是内存.磁盘.CPU三项,其中任一项资源用尽都会造成系统崩溃. 系统 内存 磁盘空间 磁盘io CPU Linux free -g df -h top AIX svmon -G/vms ...
- 补交第二周作业:学习ka li
在老师给的虚拟机上安装,试了n次都没有安装成功,百度上的说法也是众说纷纭. 之后重新安装了另一个版本的虚拟机,按照教程成功装上了ka li. 一. 安装VMtools:是为了方便宿主机与虚拟机间的文件 ...
- 1-4Controller之Middleware
1.注册中间件: 新建中间件文件:Activity <?php namespace App\Http\Middleware; use Closure; class Activity{ publi ...