• P1102 A-B数对


    P1102 A-B数对
    用map过掉,可以当高效的桶排用,map<long long,int>m;
    意思是m[long long]==int;

    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #include<map>
    #include<ctime>
    #include<cstring>
    #define inf 2147483647
    #define For(i,a,b) for(register long long i=a;i<=b;i++)
    #define p(a) putchar(a)
    #define g() getchar()
    //by war
    //2017.10.13
    using namespace std;
    long long n,c,ans;
    long long a[200010];
    map<long long,int>m;
    void in(long long &x)
    {
        long long y=1;
        char c=g();x=0;
        while(c<'0'||c>'9')
        {
        if(c=='-')
        y=-1;
        c=g();
        }
        while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
        x*=y;
    }
    void o(long long x)
    {
        if(x<0)
        {
            p('-');
            x=-x;
        }
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    long long find(long long x)
    {
        long long l=x,r=n,mid;
        while(l<r)
        {
            mid=(l+r)>>1;
            if(a[mid]>=a[x]+c)
            r=mid;
            else
            l=mid+1;
        }
        return l-1;
    }
    
    int main()
    {
        in(n),in(c);
        For(i,1,n)
        in(a[i]),m[a[i]]++;
        sort(a+1,a+n+1);
        For(i,1,n)
        ans+=m[a[i]-c];    
        o(ans);
         return 0;
    }
  • 相关阅读:
    js基础
    装饰模式,代理模式,继承
    Retrofit源码解析
    Android Studio自定义Plugin
    EMV笔记:持卡人认证(CVM)
    阿里代码规范笔记
    文章博客网址收集
    MultiDex解析
    EMV随记(1)
    RSA笔记
  • 原文地址:https://www.cnblogs.com/war1111/p/7661872.html
Copyright © 2020-2023  润新知