sequence1
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
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
.
Input
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)
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)
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
Source
/************************************************************************/
附上该题对应的中文题
sequence1
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
给定长度为n的序列a,求有多少对i,j(i<j),使得∣ai−aj∣ mod b=c
输入描述
若干组数据(大概5组)。 每组数据第一行三个整数n(1≤n≤100),b,c(0≤c<b≤109)。 接下来一行n个整数ai(0≤ai≤109)。
输出描述
对于每组数据,输出一行表示答案。
输入样例
3 3 2 1 2 3 3 3 1 1 2 3
输出样例
1 2
/****************************************************/
出题人的解题思路:
sequence1
按照题目要求,枚举任意两个数检查是否符合题意。
值得注意的是一开始所有数先对b取模这个方法是错误的。
其实此题的思路并没有多复杂,我们也不必想太多,题目怎么说,我们怎么暴力就行#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-4
using namespace std;
const int N = 105;
const int M = 15005;
const int inf = 1000000007;
const int mod = 2009;
int s[N];
int main()
{
int n,b,c,i,j,t;
while(~scanf("%d%d%d",&n,&b,&c))
{
t=0;
for(i=0;i<n;i++)
scanf("%d",&s[i]);
for(j=0;j<n;j++)
for(i=0;i<j;i++)
if(abs(s[i]-s[j])%b==c)
t++;
printf("%d\n",t);
}
return 0;
}
菜鸟成长记