心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
Use a hash table to reflect two lists of numbers.
It seems that each number cannot be less that -32768 and cannot be more that 32767.But I heard that it was not true."maxn" should be 100000,I suggest.Or you can try to find it...
Here is my code:
#include<iostream>
#include
<string.h>
#define maxn 100000
using namespace std;
long n,m;
bool a[2*maxn+7],b[2*maxn+7];
long f(long x)
{
    
return x+maxn+1;
}
int main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/
    memset(a,
false,sizeof(a));
    memset(b,
false,sizeof(b));
    cin
>>n;
    
for(long i=1;i<=n;i++)
    {
        
long t;
        cin
>>t;
        a[f(t)]
=true;
    }
    cin
>>m;
    
for(long i=1;i<=n;i++)
    {
        
long t;
        cin
>>t;
        b[f(t)]
=true;
    }
    
for(long i=-maxn;i<=maxn;i++)
        
if(a[f(i)]&&b[f(10000-i)])
        {
            cout
<<"YES"<<endl;
            
return 0;
        }
    cout
<<"NO"<<endl;
return 0;
}


posted on 2010-09-21 16:11 lee1r 阅读(170) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:数据结构

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理