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.
解法:開表格紀錄
import java.util.Scanner;
public class UVA11063 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = 1;
while (sc.hasNext()) {
int num = sc.nextInt();
int matrix[] = new int[num + 1];
int record[] = new int[20001];
boolean check = true;
for (int i = 1; i <= num; i++) {
matrix[i] = sc.nextInt();
if (matrix[i] <= matrix[i - 1] || matrix[i] < 1) {
sc.nextLine();
check = false;
break;
}
}
if (check == true)
for (int i = 1; i <= num; i++) {
for (int j = i; j <= num; j++) {
int sum = matrix[i] + matrix[j];
if (record[sum] == 0)
record[sum] = 1;
else if (record[sum] == 1) {
check = false;
break;
}
}
}
if (!check)
System.out.println("Case #" + count
+ ": It is not a B2-Sequence.");
else
System.out.println("Case #" + count + ": It is a B2-Sequence.");
count++;
System.out.println();
}
sc.close();
}
}