赞
踩
链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b。中位数是指把所有元素从小到大排列后,位于中间的数。
第一行为两个正整数n和b ,第二行为1~n 的排列。
输出一个整数,即中位数为b的连续子序列个数。
- #include<bits/stdc++.h>
- using namespace std;
- int a[100005],b[100005];
- int main()
- {
- int n,c;cin>>n>>c;
- int po,sum=0;
- for(int i=1;i<=n;i++){
- cin>>a[i];
- if(a[i]==c) po=i;
- if(a[i]<c) b[i]++;
- if(a[i]>c) b[i]--;
- b[i]+=b[i-1];
- }
- // for(int i=1;i<=n;i++) b[i]+=b[i-1];
- for(int i=po;i<=n;i++){
- for(int j=0;j<po;j++){
- if(b[i]-b[j]==0) sum++;
- }
- }
- cout<<sum;
- }

赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。