10.19T2 map

Description

  出题是一件痛苦的事情!
  题目看多了也有审美疲劳,于是我舍弃了大家所熟悉的A+B Problem,改用A-B了哈哈!
  好吧,题目是这样的:给出一串数以及一个数字C,要求计算出所有A-B=C的数对的个数。(不同位置的数字一样的数对算不同的数对)

Input

  第一行包括2个非负整数N和C,中间用空格隔开。
  第二行有N个整数,中间用空格隔开,作为要求处理的那串数。

Output

  输出一行,表示该串数中包含的所有满足A-B=C的数对的个数。

Sample Input

4 1
1 1 2 3

Sample Output

3

Hint

【数据范围】
  对于90%的数据,N<=2000;
  对于100%的数据,N<=200000。
  所有输入数据都在longint范围内。
 
 
 
map水一波
code:
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<map>
 4 using namespace std;
 5 map<int,int>check;
 6 int a[1000005];
 7 int main(){
 8     int n,c;
 9     cin>>n>>c;
10     for(int i=1;i<=n;i++){
11         cin>>a[i];
12         check[a[i]]++;
13     }
14     int ans=0;
15     for(int i=1;i<=n;i++)ans+=check[a[i]-c];
16     cout<<ans;
17     return 0;
18 }

over

原文地址:https://www.cnblogs.com/saionjisekai/p/9817855.html