水题 等差数列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 ...
随机推荐
- golang中字符串的查找方法小结
1)func Contains(s, substr string) bool这个函数是查找某个字符是否在这个字符串中存在,存在返回true 示例如下: import ( "fmt" ...
- os如何处理键盘的所有按键,显示or不显示,显示是如何显示
[0]README 0.1) source code and text decription are from orange's implemention of a os , and for comp ...
- Java 8 default 函数
我们知道在java8之前 ,一个类实现一个接口需要实现接口所有的方法, 但是这样会导致一个问题,当一个接口有很多的实现类的时候,修改这个接口就变成了一个非常麻烦的事,需要修改这个接口的所有实现类 不过 ...
- 九度OJ 1018:统计同成绩学生人数 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8807 解决:4651 题目描述: 读入N名学生的成绩,将获得某一给定分数的学生人数输出. 输入: 测试输入包含若干测试用例,每个测试用例的 ...
- 【CISCO强烈推荐】生成树 《路由协议》 卷一二 拥塞:网络延迟 阻塞:进程中 MTU QS:服务质量 OSPF RIP ISIS BGP 生成树 《路由协议》 卷一二
协议 CP/IP路由技术第一卷 作 者 (美)多伊尔,(美)卡罗尔
- jq实现批量图片上传
http://blog.csdn.net/lmj623565791/article/details/31513065 jq实现批量图片上传 http://blog.csdn.net/lmj623565 ...
- python调试利器:最直观简洁的错误日志
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-08-30 17:12:27 # @Author : Sheldon (thi ...
- @Transactional注解不回滚原因详解
最近试了试spring的回滚功能,根据网上的教程配置怎么都不好使,遂寻找答案, 网上的答案都是这么讲的: 1. 检查你方法是不是public的. 2. 你的异常类型是不是unchecked异常.如果我 ...
- python3使用pdfminer3k解析pdf文件
安装pdfminer模块 pip3 install pdfminer3k 代码如下 #!/usr/bin/env python # coding:utf8 # author:Z time:2018/7 ...
- POJ - 2031 Building a Space Station 【PRIME】
题目链接 http://poj.org/problem?id=2031 题意 给出N个球形的 个体 如果 两个个体 相互接触 或者 包含 那么 这两个个体之间就能够互相通达 现在给出若干个这样的个体 ...