# UVA 11063 B2-Sequence ## 題目連結 [UVA 11063](https://vjudge.net/problem/UVA-11063) ### 題目內容 A B2-Sequence is a sequence of positive integers 1 ≤ b~1~ < b~2~ < b~3~ . . . such that all pairwise sums b~i~ +b~j~ , where i ≤ j, are different. Your task is to determine if a given sequence is a B2-Sequence or not. ### 輸入限制 Each test case starts with 2 ≤ N ≤ 100, the number of elements in a sequence. Next line will have N integers, representing the value of each element in the sequence. Each element b~i~ is an integer such that b~i~ ≤ 10000. There is a blank line after each test case. The input is terminated by end of file (EOF). ### 輸出限制 For each test case you must print the number of the test case, starting from 1, and a message indicating if the corresponding sequence it is a B2-Sequence or not. See the sample output below. After each test case you must print a blank line. ### 解題思路 1.要很注意題目的要求,每一項都不能低於1,數列要是遞增的,可以自己加自己 2.利用vector來存取每一項相加的內容,count來算次數,如果有超過1以上代表有重複 ### 程式碼 ```cpp= #include<bits/stdc++.h> using namespace std; int main(){ int n,kase=1; while(cin>>n){ int a[n]; int ty=1; vector<int> q; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i]<1){ ty=0; } if(i!=0 && a[i]<=a[i-1]){ ty=0; } } int x=0; if(ty){ for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ x=a[i]+a[j]; q.push_back(x); if(count(q.begin(),q.end(),x)>1){ ty=0; break; } } if(ty==0){ break; } } } if(ty){ printf("Case #%d: It is a B2-Sequence.\n",kase++); } else{ printf("Case #%d: It is not a B2-Sequence.\n",kase++); } cout<<"\n"; } } ``` ## 測資 ### Sample input 4 1 2 4 8 4 3 7 10 14 ### Sample output Case #1: It is a B2-Sequence. Case #2: It is not a B2-Sequence. ## 中文題目連結 [zerojudge d123](https://zerojudge.tw/ShowProblem?problemid=d123)