2014
03-06

# Median

This problem is also easy.
Given N numbers, and please find the Median of them. Median is the number which separates the higher half the numbers given from the lower half.

There are some cases. Process to the end of file.
Each case given as N A X0 B M separates by a single space, and you are going to generate the numbers as following:
Xi = (Xi-1 * A + B) mod M
N would be less than 1000000 Both A, B, M and Xi would be a positive number less than 40000.

There are some cases. Process to the end of file.
Each case given as N A X0 B M separates by a single space, and you are going to generate the numbers as following:
Xi = (Xi-1 * A + B) mod M
N would be less than 1000000 Both A, B, M and Xi would be a positive number less than 40000.

5 73 5 97 43

25

#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1000

int a[N], n, i;
int main(){
int m, ans;
while( scanf("%d%d",&n,&m) != EOF){
ans = 0;
for(i=1; i<=n; i++)
scanf("%d", a+i);
sort(a+1, a+1+n);
while(a[(n+1)/2] != m){
a[++n] = m;
sort(a+1, a+1+n);
ans++;
}
printf("%d\n",ans);
}

return 0;
}

1. int half(int *array,int len,int key)
{
int l=0,r=len;
while(l<r)
{
int m=(l+r)>>1;
if(key>array )l=m+1;
else if(key<array )r=m;
else return m;
}
return -1;
}
这种就能避免一些Bug
l,m,r
左边是l,m;右边就是m+1,r;

2. 站长，你好！
你创办的的网站非常好，为我们学习算法练习编程提供了一个很好的平台，我想给你提个小建议，就是要能把每道题目的难度标出来就好了，这样我们学习起来会有一个循序渐进的过程！

3. Gucci New Fall Arrivals

This is really nice to know. I hope it will be successful in the future. Good job on this and keep up the good work.