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. POJ 1386 有向图欧拉通路

    题意:给你一些字符串,这些字符串可以首位相接(末位置如果和另一个字符串的首位置相同的话就可以相连) .然后问你是否可以全部连起来. 思路:就是取出每个字符串的首尾位置,然后求出出度和入度,根据有向欧拉 ...

  2. tail-head

    [root@rusky]# tail test3 #不加参数默认显示全部内容 line line2 line3 line4 line5 line6 line7 line8 line9 line10 [ ...

  3. HttpClient get返回String类型 JAVA

    public static String httpGet(String url) { // get请求返回结果 String strResult = ""; try { Defau ...

  4. ubantu命令安装banner

    banner命令可以输出图形字符 在线yum安装 $ sudo apt-get update;sudo apt-get install sysvbanner

  5. python自动化执行脚本

    ---恢复内容开始--- 1 (1)首先在你的.py文件上加上一行代码注释: #!/usr/local/bin/python2.7 (2)终端下执行: crontab -e 进入后,输入i 进入可编辑 ...

  6. SQL Server系统表讲解

    1. sysobjects http://www.cnblogs.com/atree/p/SQL-Server-sysobjects.html   2.syscomments http://www.c ...

  7. <display:column>属性解释

    参考官方网站:http://www.displaytag.org/1.2/displaytag/tagreference.html 所有属性: autolink,class,comparator,de ...

  8. xcode下载方式

    1.去AppStore下载 对于Xcode老是在AppStore升级失败,而且下载慢,可取找到了这个--> 官方 Xcode .dmg 文件下载链接:超级传送门 2.开发者中心官网下载 可参考这 ...

  9. Objective-C 异常处理

    #import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char * argv[]) { ...

  10. java下io文件切割合并功能

    package cn.stat.p1.file; import java.io.File; import java.io.FileInputStream; import java.io.FileNot ...