看了zzz的解法,场上有了思路也没时间做了。
要找出来第一次位置和最后一次位置。
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
int main() {
int tab[555];
int n,x;scanf("%d%d",&n,&x);
for(int i=1;i<=n;i++){
scanf("%d",tab+i);
}
tab[0]=0;tab[n+1]=INF;
int mid=(++n)/2;
sort(tab,tab+n+1);
int indl=lower_bound(tab+1,tab+n,x)-tab;
int indr=upper_bound(tab+1,tab+n,x)-tab;
int cnt=0;
while(!(indl<=mid&&mid<indr)){
++cnt;mid=(++n)/2;++indr;
}
printf("%d\n",cnt);
return 0;
}