UVa 11063 - B2-Sequence

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

分析:数论。计算出全部结果,排序推断相邻结果是否同样就可以。

说明:注意数据的合法性检查。

#include <algorithm>
#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,flag = 0;
		for (int i = 0 ; i < n ; ++ i)
		for (int j = i ; j < n ; ++ j)
			sum[count ++] = data[i]+data[j];
			
		if (data[0] < 1) flag = 1;
		for (int i = 1 ; i < n ; ++ i)
			if (data[i] <= data[i-1]) {
				flag = 1;
				break;
			}
		
		sort(sum, sum+count);
		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;
}







posted @ 2016-03-28 21:58  phlsheji  阅读(513)  评论(0编辑  收藏  举报