HDU 5701 中位数计数
来源:互联网 发布:网络笑话段子 编辑:程序博客网 时间:2024/05/08 23:37
Problem Description
中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数。
现在有n个数,每个数都是独一无二的,求出每个数在多少个包含其的区间中是中位数。
Input
多组测试数据
第一行一个数n(n≤8000)
第二行n个数,0≤每个数≤109
Output
N个数,依次表示第i个数在多少包含其的区间中是中位数。
Sample Input
5
1 2 3 4 5
Sample Output
1 2 3 2 1
解题思路
暴力
AC代码
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <cstring>#include <iostream>using namespace std;int main() { int n; int num[8005], cnt[16005]; while (scanf("%d", &n) != EOF) { for (int i = 1; i <=n; ++i) { scanf("%d", &num[i]); } for (int i = 1; i <= n; ++i) { int ret = 1, cur = 0; memset(cnt, 0, sizeof(cnt)); for (int j = i - 1; j > 0; --j) { if (num[j] > num[i]) { cur++; } if (num[j] < num[i]) { cur--; } cnt[cur + 8000]++; } ret += cnt[8000]; cnt[8000]++; cur = 0; for (int j = i + 1; j <= n; ++j) { if (num[j] > num[i]) { cur++; } if (num[j] < num[i]) { cur--; } ret += cnt[8000 - cur]; } printf("%s%d", i == 1 ? "" : " ", ret); } printf("\n"); } return 0;}
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5701
0 0
- HDU 5701 中位数计数
- hdu 5701 中位数计数
- HDU-5701-中位数计数
- HDU 5701 中位数计数
- HDU 5701:中位数计数
- HDU 5701 中位数计数
- HDU 5701 中位数计数
- HDU 5701 中位数计数
- hdu 5701 中位数计数
- hdu 5701 中位数计数
- hdu 5701 中位数计数
- hdu 5701 中位数计数
- HDU 5701中位数计数
- HDU 5701-中位数计数
- HDU 5701:中位数计数
- 【HDU】5701 - 中位数计数(计数 & 思维)
- HDU 5701 中位数计数 (暴力 思维题)
- HDU-5701-中位数计数
- EventBus的使用,数据传递
- 基数排序
- 描述使用AJAX提交请求,处理响应的基本步骤。
- jQuery源码学习(二)
- int *ptr=(int *)(&a+1)
- HDU 5701 中位数计数
- java中注解的使用与实例(一)
- 搭建struts2的helloworld
- error C3859: 超过了PCH的虚拟内存范围;请使用“-Zm33”或更大的命令行选项重新编译
- 初探React之生命周期
- 网站服务,流量监控
- 1006. 换个格式输出整数
- MyEclispe 代码自动提示显示“No Default Proposals”解决方法
- Java动态代理-创建动态类及查看其方法列表信息