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

 #include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 100005
long long num[MAXN];
bool tag[MAXN];
using namespace std;
long long getNum(long long x){
return (x)*(x+)/;
}
int main(){
long long n,d1,d2,i,j,k,left,right,l_sum,r_sum,sum;
bool isRL = false;
while(scanf("%lld%lld%lld",&n,&d1,&d2)!=EOF){
for(i = ;i < n ;i++){
scanf("%lld",&num[i]);
}
for(i = ;i < n- ; i++){
num[i] = num[i+] - num[i];
}
memset(tag,false,sizeof(tag));
l_sum = ;
r_sum = ;
sum = ;
for(i = ;i < n- ; i++)//d1区间与d2区间连在一起
{
if(tag[i] == true)
continue;
if(num[i]==d1 && num[i+]==d2){
tag[i] = true;
tag[i+] = true;
l_sum = ;
r_sum = ;
for(j = i- ; j>= ; j--){
if(num[j] == d1){
l_sum ++;
tag[j]= true;
}
else
break;
}
for(j = i+ ; j< n- ; j++){
if(num[j] == d2){
r_sum ++;
tag[j]= true;
}
else
break;
}
sum = sum + l_sum*r_sum +getNum(l_sum) + getNum(r_sum);
}
}
k = ;
for(i = ;i < n-;i++){//其余情况
if(tag[i]==true)
continue;
if(num[i]==d1){
k = ;
for(j = i+ ; j<n-;j++){
if(num[j]==d1){
k++;
i = j;
tag[j] = true;
}
else {
i = j-;
break;
}
}
sum = sum+getNum(k);
}
else if(num[i]==d2){
k = ;
for(j = i+ ; j<n-;j++){
if(num[j]==d2){
k++;
i = j;
tag[j] = true;
}
else {
i = j-;
break;
}
}
sum = sum+getNum(k);
}
else
{
continue;
}
}
sum+=n;
printf("%lld\n",sum);
}
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(模拟)

    Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence ≤i≤n) such that ≤j& ...

  3. hdoj 5400 Arithmetic Sequence

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

  4. 水题:HDU 5112 A Curious Matt

    Description There is a curious man called Matt. One day, Matt's best friend Ted is wandering on the ...

  5. 水题:HDU 5119 Happy Matt Friends

    Matt has N friends. They are playing a game together.Each of Matt's friends has a magic number. In t ...

  6. (水题)HDU - 1077 - Catching Fish - 计算几何

    http://acm.hdu.edu.cn/showproblem.php?pid=1077 很明显这样的圆,必定有两个点在边界上.n平方枚举圆,再n立方暴力判断.由于没有给T,所以不知道行不行.

  7. 构造 HDOJ 5400 Arithmetic Sequence

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

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

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

  9. hdu 1005:Number Sequence(水题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. linux下的显示有中国农历的日历ccal

    1.linux下的显示有中国农历的日历ccal

  2. golang中字符串的查找方法小结

    1)func Contains(s, substr string) bool这个函数是查找某个字符是否在这个字符串中存在,存在返回true 示例如下: import ( "fmt" ...

  3. Tsung 初步介绍安装

    tsung是erlang的一个开源的一个压力测试工具,可以测试包括HTTP, WebDAV, Mysql, PostgreSQL, LDAP, and XMPP/Jabber等服务器.针对 HTTP ...

  4. 关于一致/非一致代码段与TSS 关系的个人看法

    [0]概念定义 0.1)一致代码段: 简单理解,就是操作系统拿出来被共享的代码段,可以被低特权级的用户直接调用访问的代码, 但是特权级高的程序不允许访问特权级低的数据. 通常这些共享代码,是" ...

  5. 8148之更换摄像头出现异常---REISZER OVERFLOW OCCURED: RESTARTING

    my iss config as: rsz_reg->SRC_VSZ  = 1079;//715;    rsz_reg->SRC_HSZ  = 1919;//1277; rszA_reg ...

  6. 机器学习三 -- 用Python实现K-近邻算法

    Python语言实现机器学习的K-近邻算法 写在前面 额...最近开始学习机器学习嘛,网上找到一本关于机器学习的书籍,名字叫做<机器学习实战>.很巧的是,这本书里的算法是用Python语言 ...

  7. Swift———a Glance(极客学院)笔记

    http://www.swiftv.cn/course/hw4sysi7 本课程很短,加起来一个小时,适合作为一个快速了解.   两本书: apple官方<The Swift Programmi ...

  8. Java 学习 day04

    17-数组(概述-内存结构) 概念:同一种类型数据的集合,其实数组就是一个容器. 可以自动给数组中的元素从0开始编号,方便操作这些元素. int[] x = new int[3]; 01-数组(静态初 ...

  9. 在高通平台Android环境下编译内核模块【转】

    本文转载自:http://blog.xeonxu.info/blog/2012/12/04/zai-gao-tong-ping-tai-androidhuan-jing-xia-bian-yi-nei ...

  10. SpringBoot2.0之整合ActiveMQ(发布订阅模式)

    发布订阅模式与前面的点对点模式很类似,简直一毛一样 注意:发布订阅模式 先启动消费者 公用pom: <project xmlns="http://maven.apache.org/PO ...