水题 等差数列HDU 5400 Arithmetic Sequence
主要是要知道它对于等差数列的定义,单个数也可以作为等差数列且一定满足题意,另外就是要算清楚区间与区间的关系,考虑两大类情况,一种是d1区间和d2区间连在一起,另外一种情况就是其余情况。
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 100005
long long num[MAXN];
bool tag[MAXN];
using namespace std;
long long getNum(long long x){
return (x)*(x+)/;
}
int main(){
long long n,d1,d2,i,j,k,left,right,l_sum,r_sum,sum;
bool isRL = false;
while(scanf("%lld%lld%lld",&n,&d1,&d2)!=EOF){
for(i = ;i < n ;i++){
scanf("%lld",&num[i]);
}
for(i = ;i < n- ; i++){
num[i] = num[i+] - num[i];
}
memset(tag,false,sizeof(tag));
l_sum = ;
r_sum = ;
sum = ;
for(i = ;i < n- ; i++)//d1区间与d2区间连在一起
{
if(tag[i] == true)
continue;
if(num[i]==d1 && num[i+]==d2){
tag[i] = true;
tag[i+] = true;
l_sum = ;
r_sum = ;
for(j = i- ; j>= ; j--){
if(num[j] == d1){
l_sum ++;
tag[j]= true;
}
else
break;
}
for(j = i+ ; j< n- ; j++){
if(num[j] == d2){
r_sum ++;
tag[j]= true;
}
else
break;
}
sum = sum + l_sum*r_sum +getNum(l_sum) + getNum(r_sum);
}
}
k = ;
for(i = ;i < n-;i++){//其余情况
if(tag[i]==true)
continue;
if(num[i]==d1){
k = ;
for(j = i+ ; j<n-;j++){
if(num[j]==d1){
k++;
i = j;
tag[j] = true;
}
else {
i = j-;
break;
}
}
sum = sum+getNum(k);
}
else if(num[i]==d2){
k = ;
for(j = i+ ; j<n-;j++){
if(num[j]==d2){
k++;
i = j;
tag[j] = true;
}
else {
i = j-;
break;
}
}
sum = sum+getNum(k);
}
else
{
continue;
}
}
sum+=n;
printf("%lld\n",sum);
}
return ;
}
水题 等差数列HDU 5400 Arithmetic Sequence的更多相关文章
- hdu 5400 Arithmetic Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5400 Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Ot ...
- hdu 5400 Arithmetic Sequence(模拟)
Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence ≤i≤n) such that ≤j& ...
- hdoj 5400 Arithmetic Sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5400 水题 #include<stdio.h> typedef long long LL; ...
- 水题:HDU 5112 A Curious Matt
Description There is a curious man called Matt. One day, Matt's best friend Ted is wandering on the ...
- 水题:HDU 5119 Happy Matt Friends
Matt has N friends. They are playing a game together.Each of Matt's friends has a magic number. In t ...
- (水题)HDU - 1077 - Catching Fish - 计算几何
http://acm.hdu.edu.cn/showproblem.php?pid=1077 很明显这样的圆,必定有两个点在边界上.n平方枚举圆,再n立方暴力判断.由于没有给T,所以不知道行不行.
- 构造 HDOJ 5400 Arithmetic Sequence
题目传送门 题意:问有多少个区间,其中存在j使得ai + d1 == ai+1(i<j) && ai + d2 == ai+1 (i>j) 构造:用c1[i], c2[i] ...
- (模拟)Arithmetic Sequence -- HDU -- 5400
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5400 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hdu 1005:Number Sequence(水题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- spark on yarn 配置history server
spark在yarn模式下配置history server 1.建立hdfs文件– hadoop fs -mkdir /user/spark– hadoop fs -mkdir /user/spark ...
- a标签javascript传参不正确的解决办法!
代码部分: <a href="javascript:void(0);" onClick="findList(${goodsClassify.id})"&g ...
- 目标检测之行人检测(Pedestrian Detection)---行人检测之简介0
一.论文 综述类的文章 [1]P.Dollar, C. Wojek,B. Schiele, et al. Pedestrian detection: an evaluation of the stat ...
- 导出到Excel中NPOI
源地址:http://www.cnblogs.com/dreamof/archive/2010/06/02/1750151.html\ 1.NPOI官方网站:http://npoi.codeplex. ...
- python 基础 4.0 函数的一般形式及传参
#/usr/bin/python #coding=utf-8 #@Time :2017/10/23 15:58 #@Auther :liuzhenchuan #@File :函数的一般形式.p ...
- 【BZOJ1835】[ZJOI2010]base 基站选址 线段树+DP
[BZOJ1835][ZJOI2010]base 基站选址 Description 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离第1个村庄的距离为Di.需要在这些村庄中建立不超过K个通讯 ...
- Runnable 和 Callable的区别
Runnable 与 Callable的区别: (1)Callable规定的方法是call(),Runnable规定的方法是run(). (2)Callable的任务执行后可返回值,而Runnable ...
- ArcGIS api for javascript 离线部署
一.说明: 1.本篇文章以及之后的相关的文章所使用的ArcGIS API for javascript 的版本是3.3.初学者为了学习简单,可以引用在线的 Javascript.但是如果只能连接内网, ...
- curl post 请求 es 数据 REST 批量删除
curl -d "keyword=牛" http://api.com/path/index curl模拟http发送get或post接口测试 - 一生守候 - 博客园 http ...
- RocksDB
RocksDB RocksDB is a high performance[1][2][3][4][5] embedded database for key-value data. It is a f ...