hdu 5400 Arithmetic Sequence(模拟)
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.
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|≤).
For each test case, print the answer.
-
-
#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(模拟)的更多相关文章
- hdu 5400 Arithmetic Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5400 Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Ot ...
- 水题 等差数列HDU 5400 Arithmetic Sequence
主要是要知道它对于等差数列的定义,单个数也可以作为等差数列且一定满足题意,另外就是要算清楚区间与区间的关系,考虑两大类情况,一种是d1区间和d2区间连在一起,另外一种情况就是其余情况. #includ ...
- hdoj 5400 Arithmetic Sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5400 水题 #include<stdio.h> typedef long long LL; ...
- 构造 HDOJ 5400 Arithmetic Sequence
题目传送门 题意:问有多少个区间,其中存在j使得ai + d1 == ai+1(i<j) && ai + d2 == ai+1 (i>j) 构造:用c1[i], c2[i] ...
- (模拟)Arithmetic Sequence -- HDU -- 5400
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5400 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- HDU 5860 Death Sequence(死亡序列)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 1711 Number Sequence(数列)
HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU 1005 Number Sequence(数列)
HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- Arithmetic Sequence(dp)
Arithmetic Sequence Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 51 Solved: 19[Submit][Status][We ...
随机推荐
- servletContext百科
servletContext 编辑 servletContext接口是Servlet中最大的一个接口,呈现了web应用的Servlet视图.ServletContext实例是通过 getServl ...
- JS 中的引用
首先有一个全局变量 JsonArry={"key":"value"}; 假设这个object为{"你好":"引用"} ...
- Android学习之路——Android四大组件之activity(二)数据的传递
上一篇讲了activity的创建和启动,这一篇,我们来讲讲activity的数据传递 activity之间的数据传递,这里主要介绍的是activity之间简单数据的传递,直接用bundle传递基本数据 ...
- mysql数据库的高可用方法总结
高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一 些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无 ...
- Solr的安装
1. JDK要求 Solr 4.10 要求JDK版本必须是1.7或更高. 下载地址: http://www.apache.org/dyn/closer.cgi/lucene/solr/ 下载得到z ...
- eclipse与github建立版本关联、git使用说明
1.在eclipse下建一个project :aa 2.打开git bush,进入aa目录下:cd /d/MyWorkspace/aa 3.git init 4.git add -A 5.git co ...
- css变形几大属性
1.transform: transform-function() * | none; transform-function: translate().scale().rotate().skew(). ...
- PartialView 加载Js
地址记录:http://stackoverflow.com/questions/21186505/including-script-specific-to-an-asp-net-mvc4-view-o ...
- mysql/tokudb安装
一.环境要求: Operating Systems:64-bit Linux Memory: >=1G 二.安装步骤 1.下载安装包mysql-5.5.41-tokudb-7.5. ...
- 深入研究MiniMVC之后续篇
今天在园子看到<深入研究 蒋金楠(Artech)老师的 MiniMvc(迷你 MVC),看看 MVC 内部到底是如何运行的>之后,本来是不打算开博来续这个后传,不过,在那边回了个评论之后, ...