题意:给定$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的更多相关文章

  1. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  2. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  3. 2016暑假多校联合---Substring(后缀数组)

    2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...

  4. 2016暑假多校联合---To My Girlfriend

    2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...

  5. 2016暑假多校联合---A Simple Chess

    2016暑假多校联合---A Simple Chess   Problem Description There is a n×m board, a chess want to go to the po ...

  6. HDU 5792---2016暑假多校联合---World is Exploding

    2016暑假多校联合---World is Exploding Problem Description Given a sequence A with length n,count how many ...

  7. 2016暑假多校联合---Another Meaning

    2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...

  8. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  9. Contest1592 - 2018-2019赛季多校联合新生训练赛第二场(部分题解)

    Contest1592 - 2018-2019赛季多校联合新生训练赛第二场 D 10248 修建高楼(模拟优化) H 10252 组装玩具(贪心+二分) D 传送门 题干 题目描述 C 市有一条东西走 ...

  10. Contest1585 - 2018-2019赛季多校联合新生训练赛第一场(部分题解)

    Contest1585 - 2018-2019赛季多校联合新生训练赛第一场 C 10187 查找特定的合数 D 10188 传话游戏 H 10192 扫雷游戏 C 传送门 题干: 题目描述 自然数中除 ...

随机推荐

  1. [19/03/24-星期日] 容器_Collection(集合、容器)之List(表,有顺序可重复)

    一. 概念&方法 Collection 表示一组对象,它是集中.收集的意思.Collection接口的两个子接口是List.Set接口. 由于List.Set是Collection的子接口,意 ...

  2. 【luogu P4231 三步必杀】 题解

    题目链接:https://www.luogu.org/problemnew/show/P4231 诶 我很迷啊..这跟树状数组有什么关系啊...拿二阶差分数组过了..? #include <cs ...

  3. GYM 101550 G.Game Rank(模拟)

    The gaming company Sandstorm is developing an online two player game. You have been asked to impleme ...

  4. 下载YouTube视频的网站和工具

    1.界面友好,可选择的清晰度较多(我个人用这个比较多) http://en.savefrom.net/ 2.几乎可以解析到所有的清晰度 http://www.clipconverter.cc 3.可选 ...

  5. vue 集成百度富文本编辑器

    <template> <div> <textarea style="display:none" id="editor_content&quo ...

  6. TinyMCE(富文本编辑器)在Asp.Net中的使用方法

    TinyMCE(富文本编辑器)在Asp.Net中的使用方法   转至:http://www.cnblogs.com/freeliver54/archive/2013/02/28/2936506.htm ...

  7. iOS之一些实用的Demo

    图像浏览及处理 FLAnimatedImage - gif播放处理的工具. CLImageEditor - 超强的图片编辑库,快速帮你实现旋转,防缩,滤镜等等一系列麻烦的事情. ios-image-f ...

  8. c++cmb

    #include<windows.h> #include<bits/stdc++.h> using namespace std; ]; int main() { printf( ...

  9. git 本地分支与远程仓库分支关联

    当我们从远程仓库项目克隆到本地后,会自动创建本地master分支,并且与远程仓库主分支关联.如果我们需要在本地创建一个分支并且与远程仓库的origin/xxx分支关联,则可以通过以下命令实现 git ...

  10. cent os 上安装 matlab

    下载和安装可以参考,这个链接: https://lanseyujie.com/post/matlab-download-and-activate.html 上面这链接,在创建桌面快捷键时,未能创建,c ...