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 ...
随机推荐
- django搭建web (四) models.py
demo 该demo模型主要是用于问题,选择单个或多个答案的问卷形式应用 # -*- coding: utf-8 -*- from __future__ import unicode_literals ...
- css3 文字的设置
1.text-shadow 有3个length参数,第1个表示水平偏移,第2个表示垂直偏移,第3个表示模糊(可选) .text11{text-shadow: 3px 3px 5px #f00 ;col ...
- 201421123042 《Java程序设计》第12周
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...
- 11-移动端开发教程-zepto.js入门教程
Zepto.js是一个轻量级的针对现代浏览器的JavaScript库, 它与jquery有着类似的api. 如果你会用jquery,那么你也会用zepto. 1. Why Zepto.js? API类 ...
- [Redis源码阅读]redis持久化
作为web开发的一员,相信大家的面试经历里少不了会遇到这个问题:redis是怎么做持久化的? 不急着给出答案,先停下来思考一下,然后再看看下面的介绍.希望看了这边文章后,你能够回答这个问题. 为什么需 ...
- Jenkins+maven+git配置
1) 安装maven 如下图我已装好maven(这是我很早以前装的,安装教程大家可以百度一下,很容易安装的) 2) 安装git客户端 如下图所示,我也安装好了git客户 ...
- javascript实现浏览器窗口大小被改变时触发事件的方法
转载 当浏览器的窗口大小被改变时触发的事件window.onresize 为事件指定代码: 复制代码代码如下: window.onresize = function(){ } 例如: 浏览器可见区域信 ...
- redis入门(06)各种类型的操作命令
Redis 字符串命令下表列出了常用的 redis 字符串命令:序号 命令及描述1 SET key value 设置指定 key 的值2 GET key 获取指定 key 的值.3 GETRANGE ...
- Spring Security入门(3-8)Spring Security获取session中的UserDetail
- mysql(2)—— 由笛卡尔积现象分析数据库表的连接
首先,先简单解释一下笛卡尔积. 现在,我们有两个集合A和B. A = {0,1} B = {2,3,4} 集合 A×B 和 B×A的结果集就可以分别表示为以下这种形式: A×B = {(0,2 ...