[Offer收割]编程练习赛45 register

Ended

Participants:125

Verdict:Accepted
Score:100 / 100
Submitted:2018-01-21 12:11:44

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int n;
int main()
{
   // freopen("input.txt", "r", stdin);
    scanf("%d",&n);
    while(n--){
        int a, b;
        scanf("%d%d",&a, &b);
        mp[a-b]++;
    }
    map<int,int>::iterator it;
    it = mp.begin();
    long long ans = 0;
    while(it != mp.end()){
        int num = it->first;
        if(num > 0)
            ans += (long long)mp[num] * mp[-num];
        it++;
    }
    ans += (long long)mp[0] * (mp[0]-1) / 2;
    printf("%lld\n", ans);
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX