Problem B.V字型數列
題目描述
當且僅當三元組i<j<k,且 a[i]>a[j]並且a[k]>a[j],算作一個V型數列。
輸入
第一行爲測試數據組數T
每組數據第一行爲該數組的數字個數(每組數據的個數不超過50)
接下來一行爲數組元素
輸出
輸出對應數組中符合v字形數列的個數
樣例輸入
2
3
2 1 2
5
2 1 2 1 2
樣例輸出
1
4
import java.util.Scanner;
/*
Problem B.V字型數列
題目描述:當且僅當三元組i<j<k,且 a[i]>a[j]並且a[k]>a[j],算作一個V型數列。
輸入:
第一行爲測試數據組數T
每組數據第一行爲該數組的數字個數(每組數據的個數不超過50)
接下來一行爲數組元素
輸出:
輸出對應數組中符合v字形數列的個數
樣例輸入:
2
3
2 1 2
5
2 1 2 1 2
樣例輸出
1
4
*/
public class Test{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
int n = scanner.nextInt();
for(int i = 0; i < n; i++) {
int length = scanner.nextInt();
int count = 0;
int[] nums = new int[length];
for(int j = 0; j < length; j++) nums[j] = scanner.nextInt();
for(int j = 0; j < length - 2; j++) {
for(int k = j + 1; k < length - 1; k++) {
if(nums[k] < nums[j]) {
for(int l = k + 1; l < length; l++) {
if(nums[k] < nums[l]) count++;
}
}
}
}
System.out.println(count);
}
}
}
}