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. bzoj千题计划288:bzoj1876: [SDOI2009]SuperGCD

    http://www.lydsy.com/JudgeOnline/problem.php?id=1876 高精压位GCD 对于  GCD(a, b)  a>b 若 a 为奇数,b 为偶数,GCD ...

  2. css3动画 一行字鼠标触发 hover 从左到右颜色渐变

    偶然的机会发现的这个东东 这几天做公司的官网 老板突然说出了一个外国网站 我就顺手搜了 并没有发现他说的高科技 但是一个东西深深地吸引了我 就是我下面要说的动画  这个好像不能放视频 我就简单的描述一 ...

  3. python小练习之二

    title: python小练习之二 tags: 新建,模板,小书匠 grammar_cjkRuby: true --- python小练习之二 需求:实现用户登录,用户名和密码保存到文件里,连续输入 ...

  4. IDEA插件和快捷设置

    前言 IDEA全名Intellij IDEA,是Java开发的集成环境,它有两个版本,专业版(Ultimate)和社区版(Community),专业版需要注册,而社区版不用注册,同时需要注意的是社区版 ...

  5. FTP传输文件被破坏的问题(Linux、Busybox)

    在网络设备上抓包后,通过FTP传输到本机,发现抓包文件破坏.更换tftp后文件正常,定位问题在FTP上. FTP的传输模式有两种:①ASCII  ②二进制 ①ASCII: 以ASCII编码的方式传输文 ...

  6. 操作MP3文件的元数据

    参见:http://jingyan.baidu.com/article/03b2f78c4d5eae5ea237aee7.html 一.MP3文件的元数据 一个规则的MP3文件大致含有3个部分: TA ...

  7. 新概念英语(1-13)A new dress

    What colour is Anna's hat? A:What colour is your new dress? B:It's green.Come upstairs and see it. A ...

  8. Python之编码

    一.Python2与Python3的区别 1.从宏观上考虑,Python2重复代码太多,错误率高,不够规范.Python崇尚的是语言简洁.优美.清晰.Python3更加规范,重复代码少: 2.Pyth ...

  9. jodatime 时间比较

    public ArrayList<CalcPeriod> getCalcPeriods() { DateTime now = DateTime.now(); DateTime.Proper ...

  10. python虚拟环境--virtualenv

    virtualenv 是一个创建隔绝的Python环境的工具.virtualenv创建一个包含所有必要的可执行文件的文件夹,用来使用Python工程所需的包. 安装 pip install virtu ...