【多校联合】(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 传送门 题干: 题目描述 自然数中除 ...
随机推荐
- highcharts(前端报表生成)
前端报表技术:使用 JavaScript 生成漂亮图表 百度 echarts: http://echarts.baidu.com/examples.html Funsioncharts : http: ...
- 【洛谷P1726】上白泽慧音
上白泽慧音 题目链接 强联通分量模板题,Tarjan求强联通分量,记录大小即可 #include<iostream> #include<cstring> #include< ...
- div鼠标悬停,子元素上移,鼠标移出,子元素下移动画。
HTML: <div class="edt_title" > <div id="edt_title"> <p class=&quo ...
- centos6: mysql+nginx+php
安装配置: mysql: http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/ yum repolist enabled | grep mys ...
- UIImagePickerController获取照片的实现,添加overlay方法 (相机取景框)
DEVELOPER.XIAOYAOLI 技术笔记 简单的利用UIImagePickerController调用iPhone摄像头获取照片的方法,同时介绍了怎么添加overlay,用于自定义预览界面 ...
- 节约内存:Instagram的Redis实践
Instagram可以说是网拍App的始祖级应用,也是当前最火热的拍照App之一,Instagram的照片数量已经达到3亿,而在Instagram里,我们需要知道每一张照片的作者是谁,下面就是Inst ...
- <寒假逆向学习第一天> 破解基础知识之介绍常见工具和壳的特征
对于我们新手来说,程序是什么语言编写的?程序到底有没有加壳?程序加了什么壳?一直在我们心中充满了疑惑,本文我将根据我的近期学习,总结一下常见的工具和壳的特征. 一:程序是什么语言编译的 从目前接触到程 ...
- hdu_1788_Chinese remainder theorem again (lcm
我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的: 假设m1,m2,…,mk两两互素,则下面同余方程组: x≡a1(mod m1) x≡a2(mod m2) … x≡ak(mod m ...
- github 常用
1.创建KEY,这个文件生成完了后,要保存好公钥和私钥文件 ssh-keygen -t rsa -C "abc@mail.com" 2.github上添加ssh密钥 3.拷贝公钥信 ...
- php接口编程
1:自定义接口编程 对于自定义接口最关键就是写接口文档,在接口文档中规定具体的请求地址以及方式,还有具体的参数信息 2:接口文档编写 请求地址 http://jxshop.com/Api/login ...