美文网首页
2020-07-23 A-B 数对

2020-07-23 A-B 数对

作者: JalorOo | 来源:发表于2020-07-23 21:59 被阅读0次

https://www.luogu.com.cn/problem/P1102

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include <map>
typedef long long LL;
using namespace std;

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}

LL a[200001];
map<LL,LL> m;//建立一个数字到出现次数的映射 map<num,times>
//A-B=C --> A-C=B
int main() {
    int n;//输入数字个数
    LL c;//结果=c
    LL ans = 0;//对数
    cin >> n >> c;
    for(int i=1;i<=n;i++) {
        cin >> a[i];//输入数字A
        m[a[i]]++;//a的个数增加
        a[i] -= c;//a的值减去c = b
    }
    for(int i=1;i<=n;i++){
        ans += m[a[i]];// 计算每个b的个数 即答案
    }
    cout << ans << endl;
    return 0;
}/*
5
100 -1 1 -3 0 10
100x^5-x^4+x^3-3x^2+10
 3
 -50 0 0 1
 -50x^3+1
*/

相关文章

网友评论

      本文标题:2020-07-23 A-B 数对

      本文链接:https://www.haomeiwen.com/subject/lhsklktx.html