| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
2分水过#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 50050
#define TARN 10000
int main()
{
int n1,n2, temp,nList1[MAXN],nList2[MAXN];
while (cin >> n1 && n1 > 0)
{
//输入过程
for (int i = 0; i < n1; i++)
{
cin >> nList1[i];
}
cin >> n2;
for (int i = 0; i < n2; i++)
{
cin >> nList2[i];
}
temp = 0;
//进行查找2分
for (int i = 0; i < n1; i++)
{
int l = 0, r = n2 - 1,mid;
if (nList1[i] + nList2[r] > TARN || nList1[i] + nList2[l] < TARN) continue;
while (l <= r)
{
mid = l + r;
mid /= 2;
if (nList1[i] + nList2[mid] > TARN)
l = mid+1;
else if (nList1[i] + nList2[mid] < TARN)
r = mid-1;
else
{
temp = 1;
break;
}
}
if (temp == 1)
break;
}
if (temp == 1)
{
cout << "YES"<< endl;
}
else {
cout << "NO" << endl;
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator