HDU 5567 sequence1(暴力)——BestCoder Round #63(div.2)

来源:互联网 发布:长寿 知乎 编辑:程序博客网 时间:2024/06/06 08:56

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(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 21 2 33 3 11 2 3
 

Sample Output
12
 

Source
BestCoder Round #63 (div.2)
 

/************************************************************************/

附上该题对应的中文题

sequence1

 
 
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
给定长度为nn的序列a,求有多少对i, j (i < j)i,j(i<j),使得|a_i-a_j| \ mod \ b = caiaj mod b=c
输入描述
若干组数据(大概55组)。每组数据第一行三个整数n(1 \leq n \leq 100), b, c (0 \leq c < b \leq 10^{9})n(1n100),b,c(0c<b109)。接下来一行nn个整数a_i ( 0 \leq a_i \leq 10^{9})ai(0ai109)
输出描述
对于每组数据,输出一行表示答案。
输入样例
3 3 21 2 33 3 11 2 3
输出样例
12
/****************************************************/

出题人的解题思路:

sequence1

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

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

其实此题的思路并没有多复杂,我们也不必想太多,题目怎么说,我们怎么暴力就行
#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-4using 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;}
菜鸟成长记
0 0
原创粉丝点击