首页 > 代码库 > UVa 11063 - B2-Sequence

UVa 11063 - B2-Sequence

题目:给你一组数据{ b1,b2,...,bk }中,判断是否任意两个数字的和都不同。

分析:数论。计算出所有结果,排序判断相邻结果是否相同即可。

说明:500题(⊙_⊙)。

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int data[111];
int sum[5555];

int main()
{
	int n,T = 1;
	while (~scanf("%d",&n)) {
		for (int i = 0 ; i < n ; ++ i)
			scanf("%d",&data[i]);
		int count = 0;
		for (int i = 0 ; i < n ; ++ i)
		for (int j = 0 ; j < i ; ++ j)
			sum[count ++] = data[i]+data[j];
		
		sort(sum, sum+count);
		int flag = 0;
		for (int i = 1 ; i < count ; ++ i)
			if (sum[i] == sum[i-1]) {
				flag = 1;
				break;
			}
			
		if (!flag)
			printf("Case #%d: It is a B2-Sequence.\n\n",T ++);
		else 
			printf("Case #%d: It is not a B2-Sequence.\n\n",T ++);
	}
	return 0;
}


UVa 11063 - B2-Sequence