UVa 11063 - B2-Sequence
來(lái)源:程序員人生 發(fā)布時(shí)間:2014-11-20 08:13:43 閱讀次數(shù):2670次
題目:給你1組數(shù)據(jù){ b1,b2,...,bk }中,判斷是不是任意兩個(gè)數(shù)字的和都不同。
分析:數(shù)論。計(jì)算出所有結(jié)果,排序判斷相鄰結(jié)果是不是相同便可。
說(shuō)明:注意數(shù)據(jù)的合法性檢查。
#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⑴]) {
flag = 1;
break;
}
sort(sum, sum+count);
for (int i = 1 ; i < count ; ++ i)
if (sum[i] == sum[i⑴]) {
flag = 1;
break;
}
if (!flag)
printf("Case #%d: It is a B2-Sequence.
",T ++);
else
printf("Case #%d: It is not a B2-Sequence.
",T ++);
}
return 0;
}
生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)