click here~~
***Arithmetic Sequence***
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
題目大意:就是給你n個數,然後一個d1和d2,求:
1:這個區間是一個等差數列,且公差為d1或d2;
2:若區間的下標范圍為[l,r],應有l<=i<=r,使得[l,i]范圍是公差為d1的等差數列,[i,r]范圍是公差為d2的等差數列,就是找一共有幾種排列方法
吧
解題思路:首先由至少 n 個,然後根據數據推出公式就行了,
直接給出代碼吧。。。。
#include
#include
#include
using namespace std;
const int maxn = 1e5+5;
int data[maxn];
int main()
{
int d1,d2,n,sum,j,i,t;
__int64 ans, k;
while(~scanf(%d%d%d,&n,&d1,&d2))
{
t = 1;
sum = j = 0;
ans = 0;
k = 1;
for(i=1; i<=n; i++)
scanf(%d,&data[i]);
for(i=1; i i)
ans--;
k = 1;
t = 1;
sum = i;
if(j)
i--;
}
}
}
ans += (k+1)*k/2;
if(sum+k > i)
ans--;
printf(%I64d
,ans);
}
return 0;
}