sequence1
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 219 Accepted Submission(s): 168
Problem Description
Given an array a
with length n
,
could you tell me how many pairs (i,j)
( i < j ) for abs(a
i
−a
j
) mod b=c
.
Input
Several test cases(about
5
)
For each cases, first come 3 integers, n,b,c(1≤n≤100,0≤c<b≤10
9
)![]()
Then follows n
integers a
i
(0≤a
i
≤10
9
)![]()
For each cases, first come 3 integers, n,b,c(1≤n≤100,0≤c<b≤10
Then follows n
Output
For each cases, please output an integer in a line as the answer.
Sample Input
3 3 2 1 2 3 3 3 1 1 2 3
Sample Output
1 2
题意:查看|(a[i]-a[j])|%b==c的组合有多少,i<j
思路:数据只有1k,直接暴力
ac代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#define MAXN 10000001
#define fab(a) (a)>0?(a):(-a)
#define INF 0xfffffff
#define LL long long
using namespace std;
LL a[MAXN];
int main()
{
LL n,b,c;
int i,j;
while(~scanf("%lld%lld%lld",&n,&b,&c))
{
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
LL ans=0;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
LL k=a[i]-a[j];
if(k<0) k=-k;
if(k%b==c)
ans++;
}
}
printf("%lld\n",ans);
}
return 0;
}