poj 2366 Sacrament of the sum

题目连接:http://poj.org/problem?id=2366

题意:给出一个N,N个数,一个M,M个数,问在N个数取一个数和M个数中取一个数加起来是否可能等于10000,范围是-32768~32767.

分析:水题,直接加40000,然后用数组记录就好。

代码:

#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;
#define INF 0x3f3f3f3f
typedef long long ll;
#define Max(a,b) (a>b)?a:b
#define lowbit(x) x&(-x)
  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");
}
View Code

 

posted @ 2016-08-17 18:50  wwdf  阅读(415)  评论(0编辑  收藏  举报