HDU5400 Arithmetic Sequence】的更多相关文章

解题思路:这题看懂题目是很关键的,这个区间是等差数列,且公差为d1或d2, 特别注意单个数字也为等差数列.每次求出等差数列序列长度,然后   求出对应这种长度对应有多少种组合方式,累加起来就是结果.   注意要用long long,还有注意特判数据,如 5 -1 -1 ,5 4 3 2 1: 5 1 1, 1 2 3 4 5 ; 5 1 1, 1 1 1 1 1等. #include<cstdio> int main() { ], n, d1, d2; long long sum, cnt;…
题意:http://acm.hdu.edu.cn/showproblem.php?pid=5400 思路:预处理出每个点向左和向右的最远边界,从左向右枚举中间点,把区间答案加到总答案里面.由与可能与前面的区间重叠,需要减去重复的答案,由于左边界非降,所以重叠的区间长度很容易得到. #pragma comment(linker, "/STACK:10240000") #include <map> #include <set> #include <cmath&…
http://acm.hdu.edu.cn/showproblem.php?pid=5400 Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1151    Accepted Submission(s): 501 Problem Description A sequence b1,b2,⋯,bn a…
Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence ≤i≤n) such that ≤j<i),bj+=bj+d1 and =bj+d2. Teacher Mai has a sequence a1,a2,⋯,an. He wants to know how many intervals [l,r](≤l≤r≤n) there are that al,al+,⋯,ar are (d1,d…
Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 51  Solved: 19[Submit][Status][Web Board] Description Giving a number sequence A with length n, you should choosingm numbers from A(ignore the order) which can form an arithmetic sequ…
Given an array A of integers, return the length of the longest arithmetic subsequence in A. Recall that a subsequence of A is a list A[i_1], A[i_2], ..., A[i_k]with 0 <= i_1 < i_2 < ... < i_k <= A.length - 1, and that a sequence B is arithm…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5400 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 875    Accepted Submission(s): 386 Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)…
Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1810  Solved: 311[Submit][Status][Web Board] Description Giving a number sequence A with length n, you should choosing m numbers from A(ignore the order) which can form an arithmetic…
1020: Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MB Submit:  ->打开链接<- Description Giving a number sequence A with length n, you should choosing m numbers from A(ignore the order) which can form an arithmetic sequence and make m as larg…
原题链接在这里:https://leetcode.com/problems/longest-arithmetic-sequence/ 题目: Given an array A of integers, return the length of the longest arithmetic subsequence in A. Recall that a subsequence of A is a list A[i_1], A[i_2], ..., A[i_k] with 0 <= i_1 < i…
题目如下: Given an array A of integers, return the length of the longest arithmetic subsequence in A. Recall that a subsequence of A is a list A[i_1], A[i_2], ..., A[i_k] with 0 <= i_1 < i_2 < ... < i_k <= A.length - 1, and that a sequence B is…
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence if and only if…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5400 水题 #include<stdio.h> typedef long long LL; const int MAXN = 1e5; LL cnt( int x ){ )/; } int main(){ int n; int d1, d2; int flag; int ct; long long ans; int a[MAXN]; while(~scanf("%d %d %d"…
链接:http://acmoj.shu.edu.cn/problem/533/ 题意:求一个序列中,有多少三元组(其中元素不重复)在任意的排列下能构成等差数列. 分析:等差数列:\(A_j-A_i=A_k-A_j\),即\(2A_j=A_i+A_k\),枚举\(A_i+A_j\)的所有情况对应的个数,再扫一遍求解. 先统计出每个数对应的出现次数,FFT计算出和的组合情况.但是要减去\(A_i+A_i\)得到的结果以及\(A_i+A_j\)以及\(A_j+A_i\)重复的计算. 现在对于数\(A_…
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5400 题意:给定等差数列的差值d1,d2.问长度为n的数列中有多少个满足条件的子序列,条件为子序列中存在一个xi满足前半段是差值为d1的等差数列,后半段是差值为d2的等差数列 思路: 首先预处理出来出ii这个位置向前d_1d​1​​的等差序列和向后d_2d​2​​的等差数列能延续到多长,记作l_i,r_il​i​​,r​i​​. 假设d_1\neq d_2d​1​​≠d​2​​,那么枚举中间位置.…
主要是要知道它对于等差数列的定义,单个数也可以作为等差数列且一定满足题意,另外就是要算清楚区间与区间的关系,考虑两大类情况,一种是d1区间和d2区间连在一起,另外一种情况就是其余情况. #include<iostream> #include<cstdio> #include<cstring> #define MAXN 100005 long long num[MAXN]; bool tag[MAXN]; using namespace std; long long ge…
题意: 数竞选手小r最喜欢做的题型是数列大题,并且每一道都能得到满分. 你可能不相信,但其实他发现了一个结论:只要是数列,无论是给了通项还是给了递推式,无论定义多复杂,都可以被搞成等差数列.这样,只要他精通了等差数列,他就能做出任何数列题目. 等差数列是数列的一种.在等差数列中,任何相邻两项的差相等,该差值称为公差.例如数列3,5,7,9,11,13,⋯3,5,7,9,11,13,⋯就是一个等差数列. 在这个数列中,从第二项起,每项与其前一项之差都等于2,即公差为2. 小r熟知等差数列的各种公式…
题目传送门 题意:问有多少个区间,其中存在j使得ai + d1 == ai+1(i<j) && ai + d2 == ai+1 (i>j) 构造:用c1[i], c2[i]记录i为标杆左边最多几个符合以及右边最多几个符合,那么i的贡献为(c1[i]+1) * (c2[i] + 1):当d1==d2时,找出符合的连续区间,长度记为cnt,那么贡献为(cnt+1) * cnt / 2. ;;) ; ; ;        ; ;        ;        ;          …
题目 链接 题意:给定一个数X,输出一个等差数列,使得和为X. 分析 由等差数列的定义,可见一个数就是等差数列,两个数也是等差数列 #include<bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); printf("1\n"); printf("%d\n", n); ; } (只能靠做做水题过日子了...…
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequence: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The followi…
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequence: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The followi…
/**************************Sorry. We do not have enough accepted submissions.************************/ A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is t…
1.题目大意 A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequence: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The…
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequence: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The followi…
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16733   Accepted: 8427 Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing…
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequence: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The followi…
446. Arithmetic Slices II - Subsequence Hard A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequences: 1,…
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequence: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The followi…
A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequences: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The follo…
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13636   Accepted: 6808 Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing…