题解 | 数对计数

数对计数

https://www.nowcoder.com/practice/7d05171e7e0e4c6086be233769e01d94

#include <bits/stdc++.h>
#include <map>
using namespace std;
using ll=long long;
multimap<int,int> mp;
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll c;long n;cin>>n>>c;;
    for(int i=0;i<n;i++)
    {
        ll num=0;cin>>num;
      mp.insert(make_pair(num,1));       
    }
    ll ans=0;
    for(auto nums:mp)
    {
        ans+=mp.count(nums.first+c);
    }
   cout<<ans;
    
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务