首页 > ACM题库 > HDU-杭电 > HDU 2942-Pairs[解题报告]HOJ
2014
02-24

HDU 2942-Pairs[解题报告]HOJ

Pairs

问题描述 :

Given n positive integers, is it possible to divide them into pairs so that the sum of each pair is the same?

输入:

The input contains several test cases. The first line of each case contains a single integer n (2 ≤ n ≤ 100). The second line contains n positive integers not greater than 1000. These numbers are sorted in non-decreasing order. The last case is followed by a single zero, which should not be processed.

输出:

The input contains several test cases. The first line of each case contains a single integer n (2 ≤ n ≤ 100). The second line contains n positive integers not greater than 1000. These numbers are sorted in non-decreasing order. The last case is followed by a single zero, which should not be processed.

样例输入:

4
1 3 4 6
3
1 1 1
0

样例输出:

Yes
No

//英语又没学好,题意是将n分成n/2份,判断n/2份都相等吗

#include<iostream>
using namespace std;
int a[1002];

int main()
{
	int n, i, sum=0;
	while(scanf("%d", &n) != EOF && n)
	{
		for( i=0; i < n; i++ )
			scanf("%d", a+i);
		int temp;
		if(n % 2)
		{
			printf("No\n");
			continue;
		}
		temp = a[0] + a[n-1];
		for( i=1; i < n/2; i++ )
		{
			if(a[i] +a[n-i-1] != temp)	break;
		}
		if(i == n/2)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

解题参考:http://blog.csdn.net/asure__cpp/article/details/8796071


  1. 我没看懂题目
    2
    5 6 -1 5 4 -7
    7 0 6 -1 1 -6 7 -5
    我觉得第一个应该是5 6 -1 5 4 输出是19 5 4
    第二个是7 0 6 -1 1 -6 7输出是14 7 7
    不知道题目例子是怎么得出来的