您的位置:首页 > 产品设计 > UI/UE

HDOJ 5567 sequence1 (暴力)

2015-11-23 20:50 621 查看

sequence1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 219    Accepted Submission(s): 168


[align=left]Problem Description[/align]
Given an array a
with length n,
could you tell me how many pairs (i,j)
( i < j ) for abs(ai−aj) mod b=c.
 

[align=left]Input[/align]
Several test cases(about
5)

For each cases, first come 3 integers, n,b,c(1≤n≤100,0≤c<b≤109)

Then follows n
integers ai(0≤ai≤109)

 

[align=left]Output[/align]
For each cases, please output an integer in a line as the answer.
 

[align=left]Sample Input[/align]

3 3 2
1 2 3
3 3 1
1 2 3

 

[align=left]Sample Output[/align]

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: