Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 2分水过

Posted by 814264306 at 2019-04-26 14:25:10 on Problem 2366
```#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: