HDU 6095 Rikka with Competition
来源:互联网 发布:python中函数传参数 编辑:程序博客网 时间:2024/06/06 20:31
题目链接
题目意思
给你一组n个数,代表n个选手的能量高低,现在再给你一个k,任意在n个选手中挑取两个选手比赛,如果 |ai−aj|>K那么能量高的选手获胜,另一个将被淘汰,否则两个人都有机会获胜,现在要你求有多少人有获胜的可能。
解题思路
如果把n个选手的能量值进行排序,那么两两相减,如果大于k,就结束一轮的循环,否则两人都有可能获胜,那么让ans++即可。具体过程看代码吧。
代码部分
#include <iostream>#include <cstdio>#include <string.h>#include <algorithm>#define ll long longusing namespace std;ll a[1000010];int main(){ int t; scanf("%d",&t); while(t--) { ll n,k; int ans=1; scanf("%lld%lld",&n,&k); for(int i=0; i<n; i++) { scanf("%lld",&a[i]); } sort(a,a+n); for(int i=n-1; i>0; i--) { //cout<<a[i]<<" "; if((a[i]-a[i-1])>k) break; ans++; } printf("%d\n",ans); } return 0;}
阅读全文
3 0
- HDU 6095 Rikka with Competition
- HDU 6095 Rikka with Competition
- hdu 6095-Rikka with Competition
- HDU 6095 Rikka with Competition【】
- hdu 6095-Rikka with Competition
- HDU 6095 Rikka with Competition
- 多校5 HDU-6095 Rikka with Competition
- HDU 6095 Rikka with Competition(思维)
- HDU 6095 Rikka with Competition(水~)
- HDOJ 6095-Rikka with Competition
- 刷题——hdu 6095 Rikka with Competition
- 2017多校五 1011题 hdu 6095 Rikka with Competition
- HDU 6095 Rikka with Competition【阅读题】【水题】
- hdu 多校联赛 Rikka with Competition
- Rikka with Competition(HDU 609)
- hdu2639 Rikka with Competition
- HDU6095 Rikka with Competition
- Rikka with Competition
- Python学习之基础知识
- github上的awesome
- 维普__获取页面简介
- 分数拆分【南阳oj 题目66】
- [Python]在python中获取函数的参数名和参数名的默认值
- HDU 6095 Rikka with Competition
- 【linux】cat命令
- ucbug造梦西游5修改器使用方法介绍
- hdu6069
- 4.gradient descent
- hdu 6090 Rikka with Graph
- c#将捕获异常放到日志
- 【hdu1176】免费馅饼+动态规划
- git 上传代码到码云