sequence1(暴力)

sequence1

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 42    Accepted Submission(s): 38

Problem Description
Given an array a with length n, could you tell me how many pairs (i,j) ( i < j ) for abs(aiaj) mod b=c.
 

 

Input
Several test cases(about 5)
For each cases, first come 3 integers, n,b,c(1n100,0c<b109)
Then follows n integers ai(0ai109)
 

 

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

题解:水,刚开始还以为要判断数据重复的情况呐,最后发现根本不用,是 how many pairs (i,j) ,指的是i,j的对数。。。

题意就是找 how many pairs (i,j) ( i < j ) for abs(aiaj) mod b=c.

代码:

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
LL m[110];
bool judge(int a,int c,int b){
	if((a-c)%b==0)return true;
	else return false;
}
int main(){
	int n,b,c;
	while(~scanf("%d%d%d",&n,&b,&c)){
		for(int i=0;i<n;i++)scanf("%I64d",m+i);
		LL ans=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(judge(abs(m[i]-m[j]),c,b))ans++;
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

  

 

posted @ 2015-11-21 22:01  handsomecui  阅读(291)  评论(0编辑  收藏  举报