HDU 5289 Assignment(多校联合第一场1002)

Assignment

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 617    Accepted Submission(s): 314

Problem Description

Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to some staffs who were in the same group. In a group, the difference of the
ability of any two staff is less than k, and their numbers are continuous. Tom want to know the number of groups like this.

Input

In the first line a number T indicates the number of test cases. Then for each case the first line contain 2 numbers n, k (1<=n<=100000, 0<k<=10^9),indicate the company has n persons, k means the maximum difference between abilities of staff in a group is less
than k. The second line contains n integers:a[1],a[2],…,a[n](0<=a[i]<=10^9),indicate the i-th staff’s ability.

Output

For each test。output the number of groups.

Sample Input

2
4 2
3 1 2 4
10 5
0 3 4 5 2 1 6 7 8 9

Sample Output

5
28

Hint

First Sample, the satisfied groups include:[1,1]、[2,2]、[3,3]、[4,4] 、[2,3] 

Author

FZUACM

Source

field=problem&key=2015+Multi-University+Training+Contest+1&source=1&searchmode=source" style="color:rgb(26,92,200); text-decoration:none">2015 Multi-University Training Contest 1

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int n,k;
int a[100100];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        __int64 sum = 0;
        scanf("%d%d",&n,&k);
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
        }
        int bmax,bmin;
        for(int i=0; i<n; i++)
        {
            int max = a[i],min = a[i];
            bmax = i;
            bmin = i;
            int j;
            for(j=i; j<n; j++)
            {
                if(max<a[j])
                {
                    bmax = j;
                    max = a[j];
                }
                if(min > a[j])
                {
                    bmin = j;
                    min = a[j];
                }
                if(max-min >=k)
                {
                    int k2 = 1;
                    int k1 = 1;
                    if(bmax>bmin)
                    {
                        for(int v=i; v<bmax; v++)
                        {
                            sum += k1++;
                        }
                        for(int v=bmin+1;v<bmax;v++)
                        {
                            sum -= k2++;
                        }
                        i = bmin;
                    }
                    else
                    {
                        for(int v=i; v<bmin; v++)
                        {
                            sum += k1++;
                        }
                        for(int v=bmax+1;v<bmin;v++)
                        {
                            sum -= k2++;
                        }
                        i = bmax;
                    }
                    break;
                }
            }
            if(j == n)
            {
                int pk = 1;
                for(int v=i;v<n;v++)
                {
                    sum += pk++;
                }
                i = n;
                break;
            }
        }
        printf("%I64d\n",sum);
    }
    return 0;
}

时间: 2024-11-10 12:43:05

HDU 5289 Assignment(多校联合第一场1002)的相关文章

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

http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i

hdu5289||2015多校联合第一场1002贪心+RMQ

http://acm.hdu.edu.cn/showproblem.php?pid=5289 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to

hdu5289 2015多校联合第一场1002 Assignment

题意:给出一个数列,问其中存在多少连续子区间,其中子区间的(最大值-最小值)<k 思路:设dp[i]为从区间1到i满足题意条件的解,最终解即为dp[n]: 此外 假设对于arr[i] 往左遍历 一直到arr[r] 此时从区间r到区间i满足(最大值-最小值)<k,再往左一位即越界 或者 不满足条件,此时有 dp[i] = dp[i-1] + i - r + 1; 因为数据量大 往左遍历时 可能会超时 ,所以用rmq打表 查找r时用二分 就过了 代码: #include <algorithm

hdu 4865 Peter&amp;#39;s Hobby(2014 多校联合第一场 E)

Peter's Hobby Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 545    Accepted Submission(s): 237 Problem Description Recently, Peter likes to measure the humidity of leaves. He recorded a leaf

hdu 4865 Peter&#39;s Hobby(2014 多校联合第一场 E)

题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2.给定n天的叶子湿度状态,求这n天最可能的天气情况 分析:概率dp设 dp[i][j] 表示第i天天气为j的最大概率,pre[i][j]表示第i天天气最可能为j的前一天天气,dp[i][j]=max(dp[i-1][k]+log(wePro[k][j])+log(lePro[j][lePos[i]]

hdu 4869 Turn the pokers (2014多校联合第一场 I)

Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1265    Accepted Submission(s): 465 Problem Description During summer vacation,Alice stay at home for a long time, with nothing t

hdu 4865 Peter&#39;s Hobby(2014 多校联合第一场 E)

Peter's Hobby Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 545    Accepted Submission(s): 237 Problem Description Recently, Peter likes to measure the humidity of leaves. He recorded a leaf

2014多校联合第一场

1001:Couple doubi 暴力打表找规律可知,对于任意的p. (1^i+2^i+...+(p-1)^i)%p={ 非0     ,i%(p-1)==0 0        ,  i%(p-1)!=0 } 所以,结果就很显然了. #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<c

HDU 4870 Rating (2014 多校联合第一场 J)(概率)

题意: 一个人有两个TC的账号,一开始两个账号rating都是0,然后每次它会选择里面rating较小的一个账号去打比赛,每次比赛有p的概率+1分,有1-p的概率-2分,当然如果本身是<=2分的也就还是回到0分.然后问最后其中一个账号到达20分时需要打多少次比赛. 思路: 因为每次50分,到达1000分,所以可以看做每次1分,到达20分dp[i]表示i到20的数学期望那么dp[i] = dp[i+1]*p+dp[i-2]*q+1;令t[i] = dp[i+1]-dp[i]则t[i] = (t[i