题解 | 数对计数

数对计数

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

#include <iostream>
#include <set>
using namespace std;

int main() {
    int n,c;
    cin>>n>>c;
    multiset<int> ms;

    int num;

    for(int i=0;i<n;i++){
     cin>>num;
     ms.insert(num);   
    }
	// 利用 元素值+C 的数量来解决,太妙了,还不会有重复
    int count=0;
    for(auto it:ms){
        count+=ms.count(c+it);
    }
    cout<< count;
}
// 64 位输出请用

全部评论

相关推荐

链接
海梨花:我说话难听,你这简历跟没写没啥区别,搜搜别人的简历,用心写,不要随随便便就结束了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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