HDU5567/BestCoder Round #63 (div.2) A sequence1 水

sequence1 
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
 
题解:

按照题目要求,枚举任意两个数检查是否符合题意。

值得注意的是一开始所有数先对bb取模这个方法是错误的。

///1085422276
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <stack>
using namespace std;

typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back

inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';ch=getchar();
    }return x*f;
}
//****************************************
const int N=100000+350;
#define maxn 100000+5

int main()
{
    int n,b,c,a[N];
    while(scanf("%d%d%d",&n,&b,&c)!=EOF) {
        for(int i=1;i<=n;i++) {
            scanf("%d",&a[i]);
        }int ans=0;
        for(int i=1;i<=n;i++) {
            for(int j=i+1;j<=n;j++) {
                if(abs(a[i]-a[j])%b==c) {
                    ans++;
                }
            }
        }cout<<ans<<endl;
    }
    return 0;
}
代码

 

 

 

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