HDU-5701-中位数计数
2016-05-23 19:08
344 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5701
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
Source
2016"百度之星" - 初赛(Astar Round2B)
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
Source
2016"百度之星" - 初赛(Astar Round2B)
#include <bits/stdc++.h> using namespace std; const int MAXN = 8007; int a[MAXN],cnt[MAXN<<1]; int main() { int n,ans; while(scanf("%d",&n)!=EOF) { char s=' '; for(int i=1; i<=n; ++i) scanf("%d",&a[i]); for(int i=1; i<=n; ++i) { memset(cnt,0,sizeof(cnt)); int poi=0;cnt =1; for(int j=i-1; j>0; --j) { if(a[j]<a[i])poi++; else poi--; cnt[poi+n]++; } poi=0; ans=cnt ; for(int j=i+1; j<=n; ++j) { if(a[j]>a[i])poi++; else poi--; ans+=cnt[poi+n]; } if(i==n)s='\n'; printf("%d%c",ans,s); } } return 0; } /* 5 1 4 3 2 5 */
相关文章推荐
- 微信js-sdk实现“分享到朋友圈”和“发送给朋友”
- 常用cmd命令
- Python import 和 from import区别
- hdu 1060 Leftmost Digit
- RunTime高级
- canvas之接口详解
- 手把手教你用Python爬虫煎蛋妹纸海量图片
- JQuery开发1-显示或者影藏网页部分内容
- 左式堆
- OCP(01).在linux下安装Oracle-虚拟机的安装
- 粒子滤波
- 流量测试三个工具
- Spark中组件Mllib的学习16之分布式行矩阵的四种形式
- JAVA学习笔记三之(1)键盘录入数据
- 用Python爬虫抓取煎蛋(jandan.net)无聊图和妹子图
- 数据表分割策略和实现
- Java中的多继承
- java内存泄漏
- 基于TCP协议的进程间通信
- 安装memcached中遇到的几个问题