zoukankan      html  css  js  c++  java
  • 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
    ",ans);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Java构造和解析Json数据的两种方法详解一
    微信小程序-自定义组件
    微信小程序
    微信公众号
    微信小程序
    微信小程序
    微信小程序
    vue
    vue
    sass 和 css 互转网址
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4984878.html
Copyright © 2011-2022 走看看