2017 Multi-University Training Contest
来源:互联网 发布:大数据应用系统架构 编辑:程序博客网 时间:2024/06/05 05:05
题目:
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
A wrestling match will be held tomorrow.n players will take part in it. The i th player’s strength point is ai .
If there is a match between thei th player plays and the j th 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. Aftern−1 matches, the last player will be the winner.
Now, Yuta shows the numbersn,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?
A wrestling match will be held tomorrow.
If there is a match between the
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
Now, Yuta shows the numbers
It is too difficult for Rikka. Can you help her?
Input
The first line contains a numbert(1≤t≤100) , the number of the testcases. And there are no more than 2 testcases with n>1000 .
For each testcase, the first line contains two numbersn,K(1≤n≤105,0≤K<109) .
The second line containsn numbers ai(1≤ai≤109) .
For each testcase, the first line contains two numbers
The second line contains
Output
For each testcase, print a single line with a single number -- the answer.
Sample Input
25 31 5 9 6 35 21 5 9 6 3
Sample Output
51
思路:签到题。对分值排序。获胜人数处置为1,i从大到小,如果| a[i]-a[i-1] |<=k,获胜人数+1,不然就结束循环,因为继续下去没人能赢当前这个人。
CODE:
#include<bits/stdc++.h>using namespace std;int a[100005];int main(){ int t,n,k,i; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&k); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int cnt=1; for(i=n-1;i>0;i--){ if(a[i]-a[i-1]<=k) cnt++; else break; } printf("%d\n",cnt); } return 0;}
阅读全文
0 0
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 生成比较短的Token字符串
- ValueStack的使用
- Redis
- [C/C++] static在C和C++中的用法和区别
- [noi模拟赛]math (斜率优化,未测)
- 2017 Multi-University Training Contest
- Oracle学习笔记3—子查询/集合
- 虚拟文件系统
- HDOJ 1312 Red and Black(DFS,BFS)
- MySQL 表的基本操作(一) 表的创建与修改
- Powershell学习笔记(一)
- 从入门到入门-Spring Boot-属性配置3
- post提交的数据有哪几种编码格式?能否通过URL参数获取用户账户密码
- 布谷鸟算法详细讲解