【多校联合】(HDU6095)Rikka with Competition
题意:给定$n$个数,代表$n$个选手的能量高低,现在再给一个$k$,任意在$n$个选手中挑取两个选手比赛,如果$|a_i−a_j|>K$,那么能量高的选手获胜,另一个将被淘汰,否则两个人都有机会获胜,现在要你求有多少人有获胜的可能
分析:只需要排一下序,判断$a[i]-a[i+1]>m$的个数即可。因为排序后,相邻的如果都无法满足这个条件,那他一定被淘汰;反之,他就*有可能*获胜。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PB push_back
#define REP(i,n) for(int (i)=0;(i)!=(n);++(i))
#define REP_1(i,n) for(int (i)=1;(i)<=n;++(i))
bool ok[100005];
int main()
{
int T; scanf("%d",&T);
while(T--)
{
int n,k; scanf("%d%d",&n,&k);
//printf("n,k:%d %d\n",n,k);
vector<int> vec;
REP(i,n)
{
int tmp;
scanf("%d",&tmp); vec.PB(tmp);
}
sort(vec.begin(),vec.end());
memset(ok,false,sizeof(ok));
//for(int i=0;i!=n;++i) cout<<vec[i]<<" ";cout<<endl;
int maxn=-1,ans=1;
for(int i=n-2;i>=0;--i)
{
maxn=max(maxn,vec[i+1]-vec[i]);
if(maxn<=k) ans++;
}
printf("%d\n",ans);
}
return 0;
}
【多校联合】(HDU6095)Rikka with Competition的更多相关文章
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- 2016暑假多校联合---Substring(后缀数组)
2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...
- 2016暑假多校联合---To My Girlfriend
2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- HDU 5792---2016暑假多校联合---World is Exploding
2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...
- 2016暑假多校联合---Another Meaning
2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
- Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)
Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...
- Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)
Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...
随机推荐
- Linux---more命令学习
More命令 more命令一般用于分页显示文件的内容,more会显示文件第一屏的内容,在屏幕的底部,more用反白字体显示文件的百分比,这时如果按空格键,文件的一下屏内容会显示出来,如果按回车键,显示 ...
- 【洛谷P1367】蚂蚁
蚂蚁 [题目描述] 在一根无限长的木棍上,用n只蚂蚁,每只蚂蚁有一个初始位置和初始朝向,蚂蚁们以每秒一个单位的速度向前移动,当两只蚂蚁相遇时,它们会掉头(掉头时间忽略不计).现给出每只蚂蚁的初始位置和 ...
- 微软.net framework 源码学习
1. 直接下载.NET Framework源代码(下载地址),然后用Visual Studio打开查看. 2. 在线查看,网址:http://referencesource.microsoft.com ...
- vue进阶语法及生命周期函数
1.calss和style绑定 操作元素的 class 列表和内联样式style是数据绑定的一个常见需求,它两都是属性,所以可以通过v-bind来绑定 1.1绑定HTML class 可以给v-bin ...
- mycat的安装及配置文件应用
table:逻辑一 mycat的安装 1 基于jdk运行 2 获取安装包 3 解压 tar -xf Mycat***.tar.gz 4 测试运行 mycat的根目录中bin保存了mycat的核心命令文 ...
- SpringBoot非官方教程 | 第十六篇:用restTemplate消费服务
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot11-restTemplate/ 本文出自方志朋的 ...
- iOS Xcode 小技巧,提升理解查询能力,Command + 点击鼠标右键 Jump to Definition等
前言: 介绍下Xcode 小技巧,以及一下快捷键,让你调试程序更加出类拔萃,安排! Command + 点击鼠标右键 Jump to Definition,可能你平时也在用,但是你明白全部的用法吗,试 ...
- ABAP术语-Data Transfer
Data Transfer 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/22/1048286.html The entire proces ...
- MHA实现mysql高可用复制集群
MHA简述 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件.在My ...
- Keras模型的保存方式
Keras模型的保存方式 在运行并且训练出一个模型后获得了模型的结构与许多参数,为了防止再次训练以及需要更好地去使用,我们需要保存当前状态 基本保存方式 h5 # 此处假设model为一个已经训练好的 ...