码迷,mamicode.com
首页 > 其他好文 > 详细

sequence1(暴力)

时间:2015-11-21 22:34:42      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

  

 

sequence1(暴力)

标签:

原文地址:http://www.cnblogs.com/handsomecui/p/4984878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!