Problem Description
A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence if and only if there exist i(≤i≤n) such that for every j(≤j<i),bj+=bj+d1 and for every j(i≤j<n),bj+=bj+d2.

Teacher Mai has a sequence a1,a2,⋯,an. He wants to know how many intervals [l,r](≤l≤r≤n) there are that al,al+,⋯,ar are (d1,d2)-arithmetic sequence.
 
Input
There are multiple test cases.

For each test case, the first line contains three numbers n,d1,d2(≤n≤,|d1|,|d2|≤), the next line contains n integers a1,a2,⋯,an(|ai|≤).
 
Output
For each test case, print the answer.
 
Sample Input
  - 
-
 
Sample Output

 
Author
xudyh
 
Source
 
 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100006
#define ll long long
int n,k1,k2;
int a[N];
int dp[N];
int main()
{
while(scanf("%d%d%d",&n,&k1,&k2)==)
{
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
} memset(dp,,sizeof(dp));
for(int i=;i<n;i++)
{
if(a[i+]==a[i]+k1)
dp[i+]=;
else if(a[i+]==a[i]+k2)
dp[i+]=;
else dp[i+]=;
} ll ans=;
ll tmp=;
for(int i=;i<=n;i++)
{
if(dp[i]==)
{
if(dp[i-]==)
{
tmp=;
}
else
tmp++;
ans=ans+tmp+;
}
else if(dp[i]==)
{
tmp++;
ans=ans+tmp+;
}
else
{
ans++;
tmp=;
} }
printf("%I64d\n",ans);
}
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

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

  3. hdoj 5400 Arithmetic Sequence

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

  4. 构造 HDOJ 5400 Arithmetic Sequence

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

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

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

  6. HDU 5860 Death Sequence(死亡序列)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  7. HDU 1711 Number Sequence(数列)

    HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  8. HDU 1005 Number Sequence(数列)

    HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...

  9. Arithmetic Sequence(dp)

    Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 51  Solved: 19[Submit][Status][We ...

随机推荐

  1. Xcode开启gcc/g++

    Apple announced Xcode 4.3 for OSX Lion and 4.4 for OSX Mountain Lion last week. The major difference ...

  2. Jmeter压力测试环境准备

    Jmeter性能监控 配置好测试机器上的jmeter环境:http://jmeter-plugins.org/downloads/all/ 网站下载两个东西: JMeterPlugins-Standa ...

  3. Tips:javascript 图片放大和取得尺寸

    1)获取图片尺寸 <img src="http://img.my.csdn.net/uploads/201309/03/1378223257_7957.jpg" alt=&q ...

  4. [ES6] Export class and variable

    Export variable: export const MAX_USERS = 3; export const MAX_REPLIES = 3; Export default class: exp ...

  5. boost之ThreadPool

    threadpool是基于boost库实现的一个线程池子库,但线程池实现起来不是很复杂.我们从threadpool中又能学到什么东西呢? 它是基于boost库实现的,如果大家对boost库有兴趣,看看 ...

  6. java设计模式---原型模式

    原型模式(Prototype):用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 原型模式结构图 通俗来说:原型模式就是深拷贝和浅拷贝的实现. 浅拷贝 只实现了值拷贝,对于引用对象还是 ...

  7. virtual-虚方法

    看来本人理论果然不行啊,这个东西折腾死我了.即便是到现在,还是云里雾里.... 个人认为virtual的特点就是可以被override而不是必需的,到目前为止我用它的地方也比较少. public cl ...

  8. htm初学笔记

    一.什么是html HTML(HyperText Markup Language):超文本标记语言,一种纯文本类型的语言 --使用带有尖括号的“标记”将网页中的内容逐一标识出来 用来设计网页的标记语言 ...

  9. ref参数的用途

    ref参数 能够将一个变量带入方法进行改变,改变完成后再将改变完成后的变量带出方法 ref参数要求在方法外必须为值赋值,而方法内可以不赋值 static void Main(string[] arr) ...

  10. 截取字符串 substring substr slice

    截取字符串   substring 方法用于提取字符串中介于两个指定下标之间的字符  substring(start,end) 开始和结束的位置,从零开始的索引 参数     描述 start     ...