Sample Input
5 2 -2
0 2 0 -2 0
5 2 3
2 3 3 3 3
 
Sample Output
12
5

求最多多少序列满足,前半部分满足d(j+1) = d(j)+d1,后半部分d(j+1)= d(j)+d2,或者只满足其中一个。

假设可以找出长度为x的序列,则有x-1 + x-2 + .... + 1种。所以从头到尾找一遍即可。

#include <iostream>
#include <cstdio> using namespace std;
typedef long long ll; int num[101000];
int sta[101000]; ll p(ll n)
{
return (1+n)*n/2;
} int main()
{
int n, d1, d2; while(scanf("%d%d%d", &n, &d1, &d2)!=EOF)
{
scanf("%d", num+1);
for(int i=2; i<=n; i++)
{
scanf("%d", num+i);
if(num[i]==(num[i-1]+d1)) sta[i] = 1;
else if(num[i]==(num[i-1]+d2)) sta[i] = 2;
else sta[i] = 0;
}
// for(int i=1; i<=n; i++) printf("%d ", num[i]);
// for(int i=1; i<=n; i++) printf("%d ", sta[i]); ll re = 0;
int cur = 1;
while(cur<=n)
{
int ccur = cur+1;
bool flag = true;
while(ccur<=n)
{
if(sta[ccur]==0) break;
else if(sta[ccur]==1) ccur++;
else if(sta[ccur]==2)
{
while(ccur<=n)
{
if(sta[ccur]==2) ccur++;
else
{
flag = false;
break;
}
}
}
if(!flag) break;
}
re += p(ccur-cur-1);
if((ccur-cur)>1)
cur = ccur - 1;
else cur = ccur;
if(ccur>n) break;
} printf("%I64d\n", re+n);
}
return 0;
}

  

2015 多校联赛 ——HDU5400(水)的更多相关文章

  1. 2015 多校联赛 ——HDU5349(水)

    Problem Description A simple problem Problem Description You have a multiple set,and now there are t ...

  2. 2015 多校联赛 ——HDU5344(水)

    Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to ...

  3. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  7. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  8. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

随机推荐

  1. Alpha冲刺Day2

    Alpha冲刺Day2 一:站立式会议 今日安排: 首先完善前一天的剩余安排工作量,其次我们把项目大体分为四个模块:数据管理员.企业人员.第三方机构.政府人员.数据管理员这一模块,数据管理员又可细分为 ...

  2. JAVA_SE基础——52.匿名内部类

    电信的电箱烧了,害我断了2天网,真拿命,耽误了 Java匿名内部类的总结: 没有名字的内部类.就是内部类的简化形式.一般只用一次就可以用这种形式.匿名内部类其实就是一个匿名子类对象.想要定义匿名内部类 ...

  3. Pandas速查手册中文版

    本文翻译自文章: Pandas Cheat Sheet - Python for Data Science ,同时添加了部分注解. 对于数据科学家,无论是数据分析还是数据挖掘来说,Pandas是一个非 ...

  4. node框架koa

    node的两大常见web服务器框架有express和koa,之前已经介绍过express了现在来介绍下koa吧~ koa也是express团队的出品,意在利用es7新出的async来告别"回 ...

  5. c 语言的基本语法

    1,c的令牌(Tokens) printf("Hello, World! \n"); 这五个令牌是: printf ( "Hello, World! \n" ) ...

  6. Mysql主从复制架构实战

    [root@Mysql-master ~]# vim /etc/my.cnf log-bin=mysql-bin server-id = 1  #slave端server-id值改成2 mysql&g ...

  7. OpenShift实战(三):OpenShift持久化存储Redis

    1.模板定义 修改OpenShift自带模板 [root@master1 pv]# oc edit template redis-persistent 添加如下: 2.创建PV 编辑redis pv ...

  8. python入门(12)dict

    python入门(12)dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例 ...

  9. cv2.cornerHarris()详解 python+OpenCV 中的 Harris 角点检测

    参考文献----------OpenCV-Python-Toturial-中文版.pdf 参考博客----------http://www.bubuko.com/infodetail-2498014. ...

  10. 超简单的jQuery前台分页,不需导包

    今天我们介绍一个不需要导分页包的,非常容易上手的分页+模糊查询功能.接下来先介绍分页功能: 首先第一步,你要有个要去分页的列表.我这里敲了个简单的图书管理,作为展示的基础,它的列表为异步提交,由两部分 ...