• 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;
    }
    代码
     
  • 相关阅读:
    centos npm run build 报错
    python base64
    Emacs 常用命令
    linux 删除文件腾出空间 遇到的问题
    网速查看工具
    linux 查看当前文件夹下的文件大小
    Docker 私有仓库push
    Harbor:Http: server gave HTTP response to HTTPS client & Get https://192.168.2.119/v2/
    docker 私有仓库搭建
    linux 修改时间
  • 原文地址:https://www.cnblogs.com/zxhl/p/4984929.html
Copyright © 2020-2023  润新知