HDU5701 中位数计数【中位数+水题】

中位数计数

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2125    Accepted Submission(s): 735


Problem Description
中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数。

现在有 n个数,每个数都是独一无二的,求出每个数在多少个包含其的区间中是中位数。
 

Input
多组测试数据

第一行一个数 n(n8000)

第二行 n个数, 0每个数 109,
 

Output
N个数,依次表示第 i个数在多少包含其的区间中是中位数。
 

Sample Input

5 1 2 3 4 5
 

Sample Output

1 2 3 2 1
 

Source
2016"百度之星" - 初赛(Astar Round2B)


问题链接:HDU5701 中位数计数。

问题简述:参见上文。

问题分析统计比它大的(正)和比它小的(负)数的个数,再进行计算。

程序说明:(略)


AC的C++语言程序如下:

/* HDU5701 中位数计数 */

#include 
#include 

using namespace std;

const int MAXN = 8000;

int v[MAXN+1], count[2*(MAXN+1)];

int main()
{
    int n, ans, cnt;

    while(cin >> n) {
        for(int i=1; i<=n; i++)
            cin >> v[i];

        for(int i=1; i<=n; i++) {
            memset(count, 0, sizeof(count));

            cnt = 0;
            count[n]++;
            for(int j=1; j



你可能感兴趣的:(#,ICPC-备用二,#,ICPC-HDU,#,ICPC-水题题解一,ACM考试与比赛)