E - Rikka with Competition

2017-09-22 22:01:19

writer:pprp

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. nn players will take part in it. The iith player’s strength point is aiai.

If there is a match between the iith player plays and the jjth player, the result will be related to |ai?aj||ai?aj|. If |ai?aj|>K|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. After n?1n?1 matches, the last player will be the winner.

Now, Yuta shows the numbers n,Kn,K and the array aa 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?

InputThe first line contains a number t(1≤t≤100)t(1≤t≤100), the number of the testcases. And there are no more than 22 testcases with n>1000n>1000.

For each testcase, the first line contains two numbers n,K(1≤n≤105,0≤K<109)n,K(1≤n≤105,0≤K<109).

The second line contains nn numbers ai(1≤ai≤109)ai(1≤ai≤109).

OutputFor each testcase, print a single line with a single number -- the answer.Sample Input

2
5 3
1 5 9 6 3
5 2
1 5 9 6 3

Sample Output

5
1

代码如下:

#include <iostream>
#include <algorithm>

using namespace std;
const int maxn = 110000;
int arr[maxn];

int main()
{
    int cas;
    cin >> cas;
    while(cas--)
    {
        int n, k;
        cin >> n >> k;
        int ans = 1;
        for(int i = 0 ; i < n ; i++)
        {
            cin >> arr[i];
        }
        sort(arr,arr+n);
        for(int i = n-1; i > 0 ; i--)
        {
            if(arr[i]-arr[i-1] > k)
                break;
            ans++;
        }
        cout << ans << endl;
    }

    return 0;
}
时间: 2024-08-04 00:40:50

E - Rikka with Competition的相关文章

HDU 6095: Rikka with Competition

Rikka with Competition ///@author Sycamore ///@date 8/8/2017 #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector<int>v(n); for 

Rikka with Competition

Rikka with Competition 给出一个大小为n的集合\(\{a_i\}\),每次从集合中随机挑出一对数\(a_i,a_j\),如果\(|a_i-a_j|>K\),那么从集合中删掉较小的那个数字,否则随机删掉一个数字,显然会有一个数字保留到最后,现在询问能够有可能保留到最后一个数字的数字个数,\(n\leq 10^5\). 解 序列无序,不妨排个序构成一个序列,显然序列最后一个元素必然有机会留到最后,此时考虑倒数第二个元素,如果它和最后一个元素的差的绝对值不超过K那么也有机会保留到

Rikka with Competition hdu 6095

签到题目,排序然后按序清理掉一定会输的结果就可以. ac代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[100001]; int main() { int t; cin>>t; while(t--) { int n,k; int sum=0; scanf("%d %d&

HDU6095

Rikka with Competition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 772    Accepted Submission(s): 588 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situa

CIKM Competition数据挖掘竞赛夺冠算法陈运文

CIKM Competition数据挖掘竞赛夺冠算法陈运文 背景 CIKM Cup(或者称为CIKM Competition)是ACM CIKM举办的国际数据挖掘竞赛的名称.CIKM全称是International Conference on Information and Knowledge Management,属于信息检索和数据挖掘领域的国际著名学术会议,由ACM SIGIR分会(ACM Special Interest Group on Information Retrieval)主办.

HDU 5422:Rikka with Graph

Rikka with Graph Accepts: 353 Submissions: 1174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的: 勇太有一张nn个点mm条边的无向图,每一条边的长度都是1.现在他想再在这张图上连上一条连接两个不同顶点边,使得1号点到nn号点的最短路尽可能的短

HDU 5423:Rikka with Tree Dijkstra算法

Rikka with Tree Accepts: 207 Submissions: 815 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的: 对于一棵树TT,令F(T,i)F(T,i)为点1到点ii的最短距离(边长是1). 两棵树AA和BB是相似的当且仅当他们顶点数相同且对于任意的ii都有

hdu 5422 Rikka with Graph(简单题)

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: Yuta has a non-direct graph with n vertices and m edges. The length of each edge is 1.

hdu 5423 Rikka with Tree(dfs)

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: For a tree T, let F(T,i) be the distance between vertice 1 and vertice i.(The length of