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 ...
随机推荐
- SWFLoader交互
主应用程序: <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx=& ...
- Apache HttpComponents Client 4.0快速入门/升级-2.POST方法访问网页
Apache HttpComponents Client 4.0已经发布多时,httpclient项目从commons子项目挪到了HttpComponents子项目下,httpclient3.1和 h ...
- 关于使用mybatis插件自动生成代码
1.安装 mybatis 插件: 在 eclipse 中 点击 help-->Install New Software...--> Add --> local 选择插件中eclip ...
- Java基础知识强化63:Arrays工具类之方法源码解析
1. Arrays工具类的sort方法: public static void sort(int[] a): 底层是快速排序,知道就可以了,用空看. 2. Arrays工具类的toString方法底层 ...
- LayoutInflater 原理分析 示例
LayoutInflater简介 LayoutInflater 顾名思义就是布局填充器,做过Android界面编程,相信对这个类都比较熟悉,可能有人说,我们在activity中使用set ...
- Asp.Net WebApi+Microsoft.AspNet.WebApi.Core 启用CORS跨域访问
WebApi中启用CORS跨域访问 1.安装 Nugget包Microsoft.AspNet.WebApi.Cors This package contains the components to e ...
- svn服务器的配置步骤
1.安装客户端: TortoiseSVN-1.9.3.27038-x64-svn-1.9.3.msi下载地址:http://jaist.dl.sourceforge.net/project/torto ...
- php 之 文件操作(0524)
php中文件包含两种:文件,文件夹.文件夹又称目录 新建一个文件aa.txt和一个文件夹text,text文件夹下又包含bb.txt 一.判断文件类型filetype("./aa.txt&q ...
- C程序设计语言练习题1-10
练习1-10 编写一个将输入复制到输出的程序,并将起重的制表符替换为\t,把回退符替换成\b,把反斜杠替换为\\.这样可以将制表符和回退符以可见的方式显示出来. 代码如下: #include < ...
- C程序设计语言练习题1-4
练习1-4 编写一个程序打印摄氏温度转换为相应华氏温度的转换表. 代码如下: #include <stdio.h> // 包含标准库的信息. int main() // 定义名为main的 ...