北京邮电大学18年网研真题

ProblemB V字型数列,当且仅当三元组ia[j]并且a[k]>a[j],算作一个V型数列。

输入

第一行为测试数据组数T

每组数据第一行为该数组的数字个数

接下来一行为数组元素

输出:

输出对应数组中符合v字形数列的个数
测试数据:

2

3

2 1 2

5

2 1 2 1 2

输出:

1

4

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; //本题的关键在于:先累计左边比s[j]大的有几个、再累计右边比s【j】大的有几个,然后相乘
int ans[100]; //15
int main(){
#ifdef ONLINE_JUDGE
#else
freopen(“18V数列.txt”, “r”, stdin);
#endif
/* your code */

int t;
while(scanf("%d",&t)!=EOF){
	while(t--){
	      int x=0;
	
		  scanf("%d",&x);
		  for(int i=0;i=0;j--){
		  	 	   if(ans[j]>ans[i]){
		  	 	   	l++;                       //这个题目中是有提示的 
					  }
			   }
			   for(int k=i+1;kans[i]) r++;          //左边走和右边走是分别进行的 
		  	 		
				   }
			   
			   cnt+=l*r;
		  }
		printf("%d\n",cnt);			
	}
	
}  
return 0;    

}

你可能感兴趣的:(北京邮电大学18年网研真题)