7 条题解

  • 0
    @ 2024-9-17 15:11:15
    /*
    int      %o/%lo(八进制) %d/%i/%ld/%li(十进制) %x/%lx(十六进制)[如标名为o/lo/d/i/lo/li/x/lx即输出为八进制/十进制/十六进制]
    longlong %lld
    float    %f/%e
    double   %lf/%le
    char     %c
    char[]   %s
    'a'=97
    'z'=122
    'A'=65
    'Z'=90
    '0'=48
    '9'=57
    */
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <ctime>
    #include <limits>
    #include <assert.h>
    #include <stdlib.h>
    using namespace std;
    #define LL long long
    #define ull unsigned long long
    const int N=2e5+10;
    const int INF=0x3f3f3f3f;
    const double pi=3.1416;
    int n,c,a[N],ans;
    
    int main(){
    	cin>>n>>c;
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    	}
    	sort(a+1,a+n+1);
    	for(int i=1;i<=n;i++){
    		ans+=upper_bound(a+1,a+n+1,a[i]+c)-lower_bound(a+1,a+n+1,a[i]+c);
    	}
    	cout<<ans<<endl;
    return 0;
    }
    
    • 0
      @ 2024-7-13 11:25:55
      #include<bits/stdc++.h>
      using namespace std;
      const int N=2e5+520;
      int n,c,a[N];
      int sum;
      int main(){
      	cin>>n>>c;
      	for(int i=1;i<=n;i++){
      		cin>>a[i];
      	}
      	sort(a+1,a+n+1);
      	for(int i=1;i<=n;i++){
      		sum+=upper_bound(a+1,a+n+1,a[i]+c)-lower_bound(a+1,a+n+1,a[i]+c);
      	}
      	cout<<sum;
      	return 0;
      }
      
      • 0
        #include<bits/stdc++.h>
        using namespace std;
        map<long long,long long>t;
        int main(){
        	int n,c;
            int a[114514];
            cin>>n>>c;
            for(int i=1;i<=n;i++){
            	cin>>a[i];
            	t[a[i]-c]++;
            }
            int sum=0;
            for(int i=1;i<=n;i++){
            	sum+=t[a[i]];
            }
            cout<<sum;
            return 0;
        }
        
        • 0
          @ 2024-3-16 19:36:38
          #include <queue>
          #include <math.h>
          #include <stack>
          #include <stdio.h>
          #include <iostream>
          #include <vector>
          #include <iomanip>
          #include <string.h>
          #include <algorithm>
          using namespace std;
          #define LL long long
          const int N = 2e5 + 10;
          const int INF = 0x3f3f3f3f;
          int n;
          int s;
          int a[N];
          int ans;
          int main()
          {
          	cin >> n;
          	cin >> s;
          	for (int i = 1; i <= n; i++)
          	{
          		cin >> a[i];
          	}
          	sort(a + 1, a + n + 1);
          	for (int i = 1; i <= n; i++)
          	{
          		ans += upper_bound(a + 1, a + n + 1, a[i] + s) - lower_bound(a + 1, a + n + 1, a[i] + s);
          	}
          	cout << ans;
          	return 0;
          }
          
          
          • 0
            @ 2024-3-16 19:12:58

            题目描述

            出题是一件痛苦的事情!

            相同的题目看多了也会有审美疲劳,于是我舍弃了大家所熟悉的 A+B Problem,改用<span> </span>A-B 了哈哈!

            好吧,题目是这样的:给出一串数以及一个数字 �C,要求计算出所有 �−�=�AB=C 的数对的个数(不同位置的数字一样的数对算不同的数对)。

            输入格式

            输入共两行。

            第一行,两个整数 �N,�C

            第二行,�N 个整数,作为要求处理的那串数。

            1≤�≤2×1051n2×105,所有输入的整数绝对值均小于 230230。

            输出格式

            一行,表示该串数中包含的满足 �−�=�AB=C 的数对的个数。

            样例

            输入样例

            4 1
            1 1 2 3
            

            Copy

            输出样例

            3
            
            • 0
              @ 2024-3-9 23:35:38

              老钟别叫了

              • 0
                @ 2024-1-21 19:49:35

                cout<<? ?

                • 1

                信息

                ID
                1279
                时间
                1000ms
                内存
                256MiB
                难度
                7
                标签
                递交数
                370
                已通过
                94
                上传者