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

76 篇文章 0 订阅
35 篇文章 0 订阅

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 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)
问题描述
给定长度为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 2
1 2 3
3 3 1
1 2 3
输出样例
1
2
/****************************************************/

出题人的解题思路:

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-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;
}
菜鸟成长记
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值