Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator