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. CMDB资源配置管理项目

    浅谈ITIL TIL即IT基础架构库(Information Technology Infrastructure Library, ITIL,信息技术基础架构库)由英国政府部门CCTA(Central ...

  2. 工作中的Python脚本

    本章内容 1.rawlog处理   2.域名item接口刷新 3.备案结果查询 4.多级域名中取主域 5.发送邮件 6.通过api获取cdn edge ip 7.多线程下载 1.rawlog处理 脚本 ...

  3. XML文件中<return_code><![CDATA[SUCCESS]]></return_code>中CDATA的用法

    转义字符不合法的XML字符必须被替换为相应的实体. 如果在XML文档中使用类似"<" 的字符, 那么解析器将会出现错误,因为解析器会认为这是一个新元素的开始.所以不应该象下面 ...

  4. 最短路POJ 1062 昂贵的聘礼

    C - 昂贵的聘礼 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit St ...

  5. EasyUI 打印当前页

    function CommonPrint(printDatagrid, type) { var tableString = '<table cellspacing="0" c ...

  6. TYVJ3680 找妹子

    时间: 1000ms / 空间: 1200KiB / Java类名: Main 背景 本题由 @fjzzq2002 提供,已奖励20金币. 描述 sps是zzq的好伙伴. sps一天叫来了许多个妹子. ...

  7. net8:文本文件的创建及其读写

    原文发布时间为:2008-08-06 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  8. Python入门--1--基本中的基本

    一. 1.这是一个面向对面的编程,一种解释性语言. 2.缩进是python的灵魂,使代码变得非常简洁,正确使用冒号“:”,IDLE的       下一行会自动缩进 3.if语句中 python拒绝接受 ...

  9. SecureCRT 配置文件中 找密码

    打开本地电脑如下路径 C:\Users\XXX\AppData\Roaming\VanDyke\Config\Sessions 找到配置文件. 运行命令:python SecureCRTDecrypt ...

  10. Eclipse、IDEA安装JavaFX

    简介 JavaFX插件 e(fx)eclipse是一组工具和必要的库,它们帮助您执行JavaFX编程,确保您已经作为插件将其安装在eclipse上了. JavaFX Scene Builder Jav ...