0
点赞
收藏
分享

微信扫一扫

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


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

法一:二分查找

法二:数组(哈希)

#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");
}

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


举报

相关推荐

0 条评论