610. Number of number pairs, 610 number Pairs
★★Input file:dec.in
Output file:dec.out
Simple comparison
Time Limit: 1 s memory limit: 128 MB
DEIP
The question is a painful thing!
Questions to see more also have Aesthetic Fatigue, so I give up all the familiar A + B Problem, switch to A-B haha!
Well, the question is this: Given a string of numbers and a number C, it is required to calculate the number of all the A-B = C pairs.
(A number pair with the same number in different positions counts different number pairs)
Input Format
The first line contains two non-negative integers N and C, separated by spaces.
The second row contains N integers separated by spaces as the number of strings to be processed.
Output Format
Output a row that represents the number of all number pairs that meet A-B = C.
Sample Input
4 1
1 1 2 3
Sample Output
3
Data Limit
For 90% of data, N <= 2000;
For 100% of data, N <= 200000.
All input data is within the longint range.
'
Great map !!!
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<vector> 6 #include<map> 7 #define LL long long 8 using namespace std; 9 LL read(LL & n)10 {11 int flag=0,x=0;char c='/';12 while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}13 while(c>='0'&&c<='9')x=x*10+(c-48),c=getchar();14 if(flag)n=-x;15 else n=x;16 }17 LL n,c,p,ans=0,a[200001];18 map<LL,int>mp;19 int main()20 {21 freopen("dec.in","r",stdin);22 freopen("dec.out","w",stdout);23 read(n);read(c);24 for(int i=1;i<=n;i++)25 read(a[i]),mp[a[i]]++;26 for(int i=1;i<=n;i++)27 {LL now=a[i]-c;ans=ans+mp[now];} 28 cout<<ans;29 return 0;30 }