主要是要知道它对于等差数列的定义,单个数也可以作为等差数列且一定满足题意,另外就是要算清楚区间与区间的关系,考虑两大类情况,一种是d1区间和d2区间连在一起,另外一种情况就是其余情况。

 #include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 100005
long long num[MAXN];
bool tag[MAXN];
using namespace std;
long long getNum(long long x){
return (x)*(x+)/;
}
int main(){
long long n,d1,d2,i,j,k,left,right,l_sum,r_sum,sum;
bool isRL = false;
while(scanf("%lld%lld%lld",&n,&d1,&d2)!=EOF){
for(i = ;i < n ;i++){
scanf("%lld",&num[i]);
}
for(i = ;i < n- ; i++){
num[i] = num[i+] - num[i];
}
memset(tag,false,sizeof(tag));
l_sum = ;
r_sum = ;
sum = ;
for(i = ;i < n- ; i++)//d1区间与d2区间连在一起
{
if(tag[i] == true)
continue;
if(num[i]==d1 && num[i+]==d2){
tag[i] = true;
tag[i+] = true;
l_sum = ;
r_sum = ;
for(j = i- ; j>= ; j--){
if(num[j] == d1){
l_sum ++;
tag[j]= true;
}
else
break;
}
for(j = i+ ; j< n- ; j++){
if(num[j] == d2){
r_sum ++;
tag[j]= true;
}
else
break;
}
sum = sum + l_sum*r_sum +getNum(l_sum) + getNum(r_sum);
}
}
k = ;
for(i = ;i < n-;i++){//其余情况
if(tag[i]==true)
continue;
if(num[i]==d1){
k = ;
for(j = i+ ; j<n-;j++){
if(num[j]==d1){
k++;
i = j;
tag[j] = true;
}
else {
i = j-;
break;
}
}
sum = sum+getNum(k);
}
else if(num[i]==d2){
k = ;
for(j = i+ ; j<n-;j++){
if(num[j]==d2){
k++;
i = j;
tag[j] = true;
}
else {
i = j-;
break;
}
}
sum = sum+getNum(k);
}
else
{
continue;
}
}
sum+=n;
printf("%lld\n",sum);
}
return ;
}

水题 等差数列HDU 5400 Arithmetic Sequence的更多相关文章

  1. hdu 5400 Arithmetic Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=5400 Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Ot ...

  2. hdu 5400 Arithmetic Sequence(模拟)

    Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence ≤i≤n) such that ≤j& ...

  3. hdoj 5400 Arithmetic Sequence

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5400 水题 #include<stdio.h> typedef long long LL; ...

  4. 水题:HDU 5112 A Curious Matt

    Description There is a curious man called Matt. One day, Matt's best friend Ted is wandering on the ...

  5. 水题:HDU 5119 Happy Matt Friends

    Matt has N friends. They are playing a game together.Each of Matt's friends has a magic number. In t ...

  6. (水题)HDU - 1077 - Catching Fish - 计算几何

    http://acm.hdu.edu.cn/showproblem.php?pid=1077 很明显这样的圆,必定有两个点在边界上.n平方枚举圆,再n立方暴力判断.由于没有给T,所以不知道行不行.

  7. 构造 HDOJ 5400 Arithmetic Sequence

    题目传送门 题意:问有多少个区间,其中存在j使得ai + d1 == ai+1(i<j) && ai + d2 == ai+1 (i>j) 构造:用c1[i], c2[i] ...

  8. (模拟)Arithmetic Sequence -- HDU -- 5400

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5400 Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  9. hdu 1005:Number Sequence(水题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. markdownPad2 绿色破解版安装

    markdownpad2,默认为markdown传统风格,不能编辑分行的代码段,可以在设置里改为Github 风格,但需要付费激活,以下是绿色安装包,附激活方法 下载地址 https://pan.ba ...

  2. maven新建项目报错

    创建了一个maven项目,报错 Errors occurred during the build. Errors running builder 'Maven Project Builder' on ...

  3. 跳过权限检查,强制修改mysql密码

    windows: 1,停止MYSQL服务,CMD打开DOS窗口,输入 net stop mysql 2,在CMD命令行窗口,进入MYSQL安装目录 比如E:\Program Files\MySQL\M ...

  4. linux 配置 skywalking

    linux安装elasticsearch 一.检测是否已经安装的elasticsearch ps -aux|grep elasticsearch 二.下载elasticsearch (1)下载网站为: ...

  5. python中装饰器你真的理解吗?

    def w1(func): print('装饰器1....') def w1_in(): print('w1_in.....') func() return w1_in def w2(func): p ...

  6. JSON格式之GSON解析

    JSON格式之GSON解析 最近在做websocket相关,项目需要JSON解析.相较之下感觉google的GSON解析不错. JAVA后台 Gson提供了fromJson()方法来实现从Json相关 ...

  7. 文件查找工具Everything小工具的使用

    Everything 小工具的使用: 首先它是一款基于名称实时定位文件和目录的搜索工具,有以下几个优点: 快速文件索引 快速文件搜索 较低资源占用 轻松分享文件索引 实时跟踪文件更新 通过使用ever ...

  8. exception_action

    for i in range(3, -2, -1): try: print(4 / i) except Exception as e: print(Exception) print(e)

  9. hadoop磁盘空间不均衡的解决办法

    hadoop集群在运行一段时间后,总是会出现某台机器的磁盘使用率特别高,有的使用率特别低,针对这种情况,hadoop提供了balancer工具调整磁盘负载 使用命令:start-balancer.sh ...

  10. Java for LeetCode 134 Gas Station

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...