HDU 5400(Arithmetic Sequence-暴力找区间)
来源:互联网 发布:淘宝网民族风女装春装 编辑:程序博客网 时间:2024/06/09 20:30
Arithmetic Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 937 Accepted Submission(s): 411
Problem Description
A sequence b1,b2,⋯,bn are called (d1,d2) -arithmetic sequence if and only if there exist i(1≤i≤n) such that for every j(1≤j<i),bj+1=bj+d1 and for every j(i≤j<n),bj+1=bj+d2 .
Teacher Mai has a sequencea1,a2,⋯,an . He wants to know how many intervals [l,r](1≤l≤r≤n) there are that al,al+1,⋯,ar are (d1,d2) -arithmetic sequence.
Teacher Mai has a sequence
Input
There are multiple test cases.
For each test case, the first line contains three numbersn,d1,d2(1≤n≤105,|d1|,|d2|≤1000) , the next line contains n integers a1,a2,⋯,an(|ai|≤109) .
For each test case, the first line contains three numbers
Output
For each test case, print the answer.
Sample Input
5 2 -20 2 0 -2 05 2 32 3 3 3 3
Sample Output
125
Author
xudyh
Source
2015 Multi-University Training Contest 9
Recommend
wange2014 | We have carefully selected several similar problems for you: 5421 5420 5419 5418 5417
暴力找区间
#include<bits/stdc++.h> using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (1000000+10)typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int n;ll d1,d2,a[MAXN],b[MAXN]; int main(){//freopen("E.in","r",stdin);while(cin>>n>>d1>>d2){For(i,n) scanf("%lld",&a[i]);For(i,n-1) b[i]=a[i+1]-a[i];//For(i,n-1) cout<<b[i]<<' ';cout<<endl;if (d1==d2){ll sz=1,ans=0;Fork(i,2,n) if (a[i]-a[i-1]==d1) sz++; else ans+=sz*(sz+1)/2,sz=1;if (sz) ans+=sz*(sz+1)/2;cout<<ans<<endl; } else {ll sz=1,ans=0; bool flag=0;Fork(i,2,n){if (!flag){if (a[i]-a[i-1]==d1) sz++;else if (a[i]-a[i-1]==d2) sz++,flag=1;else ans+=sz*(sz+1)/2,sz=1,flag=0;}else{if (a[i]-a[i-1]==d2) sz++;else if (a[i]-a[i-1]==d1) ans+=sz*(sz+1)/2-1,sz=2,flag=0;else ans+=sz*(sz+1)/2,sz=1,flag=0;}}if (sz) ans+=sz*(sz+1)/2;cout<<ans<<endl; } }return 0;}
0 0
- HDU 5400(Arithmetic Sequence-暴力找区间)
- HDU 5400 Arithmetic Sequence
- hdu 5400 Arithmetic Sequence
- HDU 5400 Arithmetic Sequence
- HDU 5400 Arithmetic Sequence
- HDU 5400 Arithmetic Sequence
- hdu 5400 Arithmetic Sequence
- hdu 5400 Arithmetic Sequence
- hdu 5400 Arithmetic Sequence
- HDOJ 5400 Arithmetic Sequence 暴力枚举
- HDU-5400 Arithmetic Sequence(数学 || DP)
- hdu 5400 Arithmetic Sequence(计数)
- HDU 5400 Arithmetic Sequence(数学,容斥)
- Hdu 5400 Arithmetic Sequence 数学推理
- HDU 5400 Arithmetic Sequence(左d1等差右d2等差的区间个数)(枚举位置,求最大区间,算区间个数)
- HDU 1005 Number Sequence 找循环区间的长度
- 【HDOJ 5400】Arithmetic Sequence
- hdu 5400 Arithmetic Sequence(水题一道)
- python_学习笔记0824
- Linux 下的shell快捷键
- cookie 和session 的区别
- Linux系统内存管理及相关操作函数
- 创业团队新产品开发模式----寻找一个可持续升级、重复、盈利的模式
- HDU 5400(Arithmetic Sequence-暴力找区间)
- hdu5273(区间DP)
- I love sneakers!(分组背包HDU3033)
- 一些文章收藏
- pomodoro源代码
- 利用POI在Excel文档任意单元格写入数据
- codecombat之边远地区的森林12-22关及地牢39关代码分享
- HDU 5402(Travelling Salesman Problem-构造矩阵对角最长不相交路径)
- 简述C和C++程序员学习历程