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. unittest和pytest对比

    一.用例编写规则 1.unittest提供了test cases.test suites.test fixtures.test runner相关的类,让测试更加明确.方便.可控.使用unittest编 ...

  2. x86保护模式 二 分段管理机制

    分段管理机制 段选择子和偏移地址的二维虚拟地址转换为一维的线性地址 一  段定义和虚拟地址到线性地址的转换 三个参数定义段:段基地址    段界限  和段属性    同时也是段描述符的结构 段基地址为 ...

  3. Codeforces Round #402 (Div. 2) A+B+C+D

    Codeforces Round #402 (Div. 2) A. Pupils Redistribution 模拟大法好.两个数列分别含有n个数x(1<=x<=5) .现在要求交换一些数 ...

  4. php文档php-fpm.conf配置

    cat php-fpm.conf|grep -v "^;"|grep -v "^$" [global] pid = run/php-fpm.pid   //pi ...

  5. BZOJ2707 [SDOI2012]走迷宫 【概率dp + tarjan + 高斯消元】

    题目 Morenan被困在了一个迷宫里.迷宫可以视为N个点M条边的有向图,其中Morenan处于起点S,迷宫的终点设为T.可惜的是,Morenan非常的脑小,他只会从一个点出发随机沿着一条从该点出发的 ...

  6. 【bzoj1483】[HNOI2009]梦幻布丁 set

    [bzoj1483][HNOI2009]梦幻布丁 Description N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2 ...

  7. 使用vue-cli创建项目(包含npm和cnpm的安装nodejs的安装)

    转:http://www.cnblogs.com/wisewrong/p/6255817.html vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue-cli 可以快速创建 vue ...

  8. Python脚本实现值更新事件赋值过程记录日志监控

    #LogWatch 实现值更新事件赋值过程记录日志监控 clr.AddReference('System') clr.AddReference('Kingdee.BOS') clr.AddRefere ...

  9. Laravel 控制器的response

    public function response(){ //响应json $data = [ 'errCode' => 0, 'errMsg' => 'success', 'data' = ...

  10. php——两种无限级分类

    /** * 无级递归分类 TP框架 * @param int $assortPid 要查询分类的父级id * @param mixed $tag 上下级分类之间的分隔符 * @return strin ...