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. beat冲刺计划安排

    1. 团队成员 组长:郭晓迪 组员:钟平辉 柳政宇 徐航 曾瑞 2. 主要计划安排如下: 3. 详细日程任务安排

  2. 201621123050 《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 1.2 可选:使用常规方法总结其他上课内容. L ...

  3. angular2 学习笔记 ( Dynamic Component 动态组件)

    更新 2018-02-07 详细讲一下 TemplateRef 和 ViewContainerRef 的插入 refer : https://segmentfault.com/a/1190000008 ...

  4. 新概念英语(1-119)who call out to the thieves in the dark?

    who call out to the thieves in the dark? A true story Do you like stories? I want to tell you a true ...

  5. 新概念英语(1-25)Mrs. Smith's Kitchen

    What colour is the electric cooker? Mrs. Smith's Kitchen is small. There is a refrigerator in the ki ...

  6. SiteMesh入门(1-1)SiteMesh是什么?

    1.问题的提出 在开发Web 应用时,Web页面可能由不同的人参与开发,因此开发出来的界面通常千奇百怪.五花八门,风格难以保持一致. 为了统一界面的风格,Struts 框架提供了一个标签库Tiles ...

  7. C# 客户端程序调用外部程序的三种实现

    简介 我们用C#来开发客户端程序的时候,总会不可避免的需要调用外部程序或者访问网站,本篇博客介绍了三种调用外部应用的方法,供参考 实现 第一种是利用shell32.dll,实现ShellExecute ...

  8. Mysql官方文档翻译系列14.18--MySql备份与恢复

    原文链接: (https://dev.mysql.com/doc/refman/5.7/en/innodb-backup-recovery.html) The key to safe database ...

  9. Django ORM创建数据库

    Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...

  10. xpath的一般用法与特殊用法

    # xpath的使用 安装lxml from lxml import etree Selector = etree.HTML(网页代码) Selector.xpath(一段神奇的代码) xpath的一 ...