hdoj 5400 Arithmetic Sequence】的更多相关文章

题目链接: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"…
题目传送门 题意:问有多少个区间,其中存在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. ;;) ; ; ;        ; ;        ;        ;          …
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…
主要是要知道它对于等差数列的定义,单个数也可以作为等差数列且一定满足题意,另外就是要算清楚区间与区间的关系,考虑两大类情况,一种是d1区间和d2区间连在一起,另外一种情况就是其余情况. #include<iostream> #include<cstdio> #include<cstring> #define MAXN 100005 long long num[MAXN]; bool tag[MAXN]; using namespace std; long long ge…
链接: 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: 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…
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…
题目传送门 /* Rabin_Karp:虽说用KMP更好,但是RK算法好理解.简单说一下RK算法的原理:首先把模式串的哈希值算出来, 在文本串里不断更新模式串的长度的哈希值,若相等,则找到了,否则整个模式串的长度的哈希值向右移动一位 */ /************************************************ * Author :Running_Time * Created Time :2015-8-5 14:04:26 * File Name :HDOJ_1711.…
原题链接在这里: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…
A sequence of numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4384    Accepted Submission(s): 1374 Problem Description Xinlv wrote some sequences on the paper a long time ago, they might…
Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8600    Accepted Submission(s): 3953 Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[…
Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 15017    Accepted Submission(s): 6585 Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b…
Problem Description Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep love and yearns for the boundless oceans. After graduation, he came to a coastal city and got…
题目链接: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​​,那么枚举中间位置.…
http://www.shuizilong.com/house/archives/hdu-5306-gorgeous-sequence/ Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 440    Accepted Submission(s): 87 Problem Description Th…
a[i] 表示以i字符开头的合法序列有多少个 b[i] 表示以i字符结尾的合法序列有多少个 up表示上一层的'('的相应位置 mt[i] i匹配的相应位置 c[i] 包括i字符的合法序列个数  c[i]=c[up[i]]+a[i]*b[mt[i]] 括号序列不一定是合法的.... Easy Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Sub…
题意:http://acm.hdu.edu.cn/showproblem.php?pid=5400 思路:预处理出每个点向左和向右的最远边界,从左向右枚举中间点,把区间答案加到总答案里面.由与可能与前面的区间重叠,需要减去重复的答案,由于左边界非降,所以重叠的区间长度很容易得到. #pragma comment(linker, "/STACK:10240000") #include <map> #include <set> #include <cmath&…
解题思路:这题看懂题目是很关键的,这个区间是等差数列,且公差为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;…
这道题,咋一看很像Fibonacci数列,使用递归或者改进的动态规划来解决.但是仔细一看,(1 <= n <= 100,000,000),使用这些方法,要么超时,要么肯定内存不够用,因此必须想别的办法.遇到这种情况也就只有找规律了.仔细看:f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7,因为存在取模运算,那么当n取到一定值后,f(n)肯定会重复出现.关于找规律的过程,博客园有一位朋友已经进行了详细分析了,请点击链接.下面给出最终的代码: #include&…
线段树的应用,很不错的一道题目.结点属性包括:(1)n1:1的个数:(2)c1:连续1的最大个数:(3)c0:连续0的最大个数:(4)lc1/lc0:从区间左边开始,连续1/0的最大个数:(5)rc1/rc0:从区间右边开始,连续1/0的最大个数:(6)set:置区间为0/1的标记:(7)flip:0->1, 1->0的标记.采用延迟更新.每当更新set时,flip就置为false:每当更新flip时,其实就是c1/c0, lc1/lc0, rc1/rc0的交换.对于询问最长连续1,共包括3种…
链接: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_…
题意: 数竞选手小r最喜欢做的题型是数列大题,并且每一道都能得到满分. 你可能不相信,但其实他发现了一个结论:只要是数列,无论是给了通项还是给了递推式,无论定义多复杂,都可以被搞成等差数列.这样,只要他精通了等差数列,他就能做出任何数列题目. 等差数列是数列的一种.在等差数列中,任何相邻两项的差相等,该差值称为公差.例如数列3,5,7,9,11,13,⋯3,5,7,9,11,13,⋯就是一个等差数列. 在这个数列中,从第二项起,每项与其前一项之差都等于2,即公差为2. 小r熟知等差数列的各种公式…
题目 链接 题意:给定一个数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…