2015 多校联赛 ——HDU5400(水)
0 2 0 -2 0
5 2 3
2 3 3 3 3
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(水)的更多相关文章
- 2015 多校联赛 ——HDU5349(水)
Problem Description A simple problem Problem Description You have a multiple set,and now there are t ...
- 2015 多校联赛 ——HDU5344(水)
Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to ...
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
随机推荐
- 201621123060 《Java程序设计》第六周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰 ...
- 位图(BitMap)
位图 引入:2.给40亿个不重复的无符号整数,没排过序.给一个无符号整数,如何快速判断一个数是否在这40亿个数中. [腾讯] 思路:如果内存够的话,40亿个整型使用位图存储需要500M左右的空间. 分 ...
- codves 3044 矩形面积求并
codves 3044 矩形面积求并 题目等级 : 钻石 Diamond 题目描述 Description 输入n个矩形,求他们总共占地面积(也就是求一下面积的并) 输入描述 Input Desc ...
- axios封装
前言 作为出入vue的小萌新,我在写请求的时候,也是毫不犹豫写了ajax,结果肯定是不行的... Vue 原本有一个官方推荐的 ajax 插件 vue-resource,但是自从 Vue 更新到 2. ...
- IDEA之Jrebel插件激活
问题: 码农日常中,热部署是必不可少的,而jrebel插件很好的实现热部署功能. IDEA下载jrebel插件,可以免费试用15天,但之后就无法使用.因为Jrebel是收费的. 解决方法: 楼主也是百 ...
- vue初尝试--新建项目
这是一篇技术贴--如何新建一个基于vue的项目 1.下载对应版本的nodejs安装,下载的nodejs都集成了npm,所以nodejs安装完成之后npm也对应安装完成了. 安装完成之后可以在cmd命令 ...
- php类中的$this,static,const,self这几个关键字使用方法
本篇文章主要分享一下关于php类中的$this,static,final,const,self这几个关键字使用方法 $this $this表示当前实例,在类的内部方法访问未声明为const及stati ...
- GIT入门笔记(9)- git的add和commit机制原理
工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库. Git的版本库里存了很多东西,其中最重要的就是称为stage(或者叫index)的暂存区,还有Git为我们自动创建的第一个分支mas ...
- apacheds的客户端
Apache DS管理的JAVA实现 LdapConnection connection = new LdapNetworkConnection("localhost", 1038 ...
- 英语词汇(5)followed by / sung by / written by
Sung by 演唱者; [例句]In the recording I have today, it is sung by a male alto.我今天带的唱片是由一位男高音歌手唱的. follow ...