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




#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;
}




 

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

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

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  2. hdu5289 2015多校联合第一场1002 Assignment

    题意:给出一个数列.问当中存在多少连续子区间,当中子区间的(最大值-最小值)<k 思路:设dp[i]为从区间1到i满足题意条件的解.终于解即为dp[n]. 此外 如果对于arr[i] 往左遍历 ...

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

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)

    题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...

  5. HDU 4868 Information Extraction(2014 多校联合第一场 H)

    看到这道题时我的内心是奔溃的,没有了解过HTML,只能靠窝的渣渣英语一点一点翻译啊TT. Information Extraction 题意:(纯手工翻译,有些用词可能在html中不是一样的,还多包涵 ...

  6. 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) To ...

  7. 2015 多校赛 第一场 1002 (hdu 5289)

    Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...

  8. HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场

    题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...

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

    题意: 一个人有两个TC的账号,一开始两个账号rating都是0,然后每次它会选择里面rating较小的一个账号去打比赛,每次比赛有p的概率+1分,有1-p的概率-2分,当然如果本身是<=2分的 ...

随机推荐

  1. Android开发——ThreadLocal功能介绍

    个静态的监听器对象,显然是无法接受的. 2.  使用实例 //首先定义一个ThreadLocal对象,选择泛型为Boolean类型 private ThreadLocal<Boolean> ...

  2. 五、人生苦短,我用python【第五篇】

    Python基本数据类型 运算符 1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为 ...

  3. Unity3D for iOS初级教程:Part 3/3

    转自Unity 3D for iOS 这篇文章还可以在这里找到 英语 Learn how to use Unity to make a simple 3D iOS game! 这份教程是由教程团队成员 ...

  4. 【Luogu】P2331最大子矩阵(DP)

    题目链接 这题的状态转移方程真是粗鄙. f[i][j][k]表示前i行用了j个矩阵状态为k的时候的最大值. k=0:两列都不选. k=1:取左弃右. k=2:选右弃左. k=3:左右都选,但分属于两个 ...

  5. tarjan 缩点 求 scc

    算法学自 BYVoid https://www.byvoid.com/zhs/blog/scc-tarjan/ 这个写得很清楚了 当然 你可能不这么认为 而且 如果是让我 一开始就从这个博客 学 ta ...

  6. Ionic2如何下拉刷新和上拉加载

    下拉刷新: <ion-content> <ion-refresher (ionRefresh)="doRefresh($event)"> <ion-r ...

  7. uva 12304点与直线与圆之间的关系

    Problem E 2D Geometry 110 in 1! This is a collection of 110 (in binary) 2D geometry problems. Circum ...

  8. Lucky and Good Months by Gregorian Calendar(poj 3393)

    大致题意: 科普文一篇,文章80%都是无用信息,因为都是常识,但是又不得不看,因为有20%是常人不知道的历史常识. 定义: Goog month : 该月第一个工作日为星期一的月份 Luckly mo ...

  9. BZOJ4725: [POI2017]Reprezentacje ró?nicowe

    $n \leq 1e5$,$x \leq 1e9$. 1e9呵呵,暴力处理$a_n$的前几项直到1e9.然后处理出差的数列,每次在这里面找,找得到就回答,找不到,那有贡献的只有$a_i-a_{i-1} ...

  10. 【黑科技】读写优化 orz bdd

    转自 bdd :http://www.cnblogs.com/kevince/p/3924688.html 读入优化: inline int read() { char ch; bool flag = ...