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 ...
随机推荐
- c\c++复习基础要点08--c++单例模式
单例模式有许多种实现方法,在c++中,甚至可以直接用一个全局变量做到这一点,但是这样的代码显得不优雅.使用全局对象能够保证方便地访问实例,但是不能保证只声明一个对象——也就是说除了一个全局实例外,仍然 ...
- [ES6] When should use Map instead of Object
Use Maps when keys are unknown until runtime: Map: let recentPosts = new Map(); createPost( newPost, ...
- Java可见性机制的原理
基本概念 可见性 当一个线程修改了共享变量时,另一个线程可以读取到这个修改后的值. 内存屏障(Memory Barriers) 处理器的一组指令,用于实现对内存操作的顺序限制. 缓冲行 CPU告诉缓存 ...
- .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"的问题
在.NET中使用GridView控件的在线编辑数据时,出现了“ Index was out of range. Must be non-negative and less than the size ...
- 使用Uploadify 时,同时使用了jQuery.Validition 验证控件时,在IE11上出现JS缺少对象错误。
场景: 使用jQuery.1.8.2 使用 Uploadify 3.2上传控件 使用jQuery.Validition 1.9 验证 使用IE 11 时,当鼠标点击上传按钮时,会出现JS 缺少对象错误 ...
- 网络NSURLSession
简单下载图片 dispatch_queue_t queue =dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT); dispatch_asyn ...
- 爆炸!iOS资源大礼包(持续更新...)
今天为大家整理了一些关于iOS学习的干货,献给正在奋斗的你们,首先声明一下,在整理的过程中参考了大量的博客和文章,知识的分享终究会增值,在此表示感谢,希望这篇文章给大家带来帮助. 基础部分: C语言教 ...
- arraylist的使用
ArraylistDemo package cn.stat.p6.arraylist.demo; import java.util.ArrayList; import java.util.Iterat ...
- _CrtMemBlockHeader
typedef struct _CrtMemBlockHeader{// Pointer to the block allocated just before this one:struct _Crt ...
- nginx_http核心模块(二)
对一些常用的配置项做一些解释:详细请看官方文档:http://nginx.org/en/docs/http/ngx_http_core_module.html 1. alias Syntax: ali ...