POJ 2366 Sacrament of the sum 二分查找 哈希表

题干那么长,就是在两个数组里面分别找一个数,使得和为10000

法一:二分查找

法二:数组(哈希)
转载自

https://www.cnblogs.com/wwdf/p/5781351.html

#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

int n,m,vis[1000000]={0},t,ff=0;

int main()
{

    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&t);
        vis[t+40000]=1;
    }
    scanf("%d",&m);
    for(int j=0;j<m;j++)
    {
        scanf("%d",&t);
        if(vis[50000-t])
            ff=1;
    }
    if(ff)
        puts("YES");
    else
        puts("NO");
}

在这里插入图片描述

发布了286 篇原创文章 · 获赞 57 · 访问量 324万+

猜你喜欢

转载自blog.csdn.net/L1558198727/article/details/103978677