610. Number of number pairs, 610 number Pairs

Source: Internet
Author: User

610. Number of number pairs, 610 number Pairs

★★Input file:dec.inOutput file:dec.outSimple 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 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.