百度之星 hdu5701 中位数计数
2024-09-29 06:08:47
http://acm.hdu.edu.cn/showproblem.php?pid=5701
给出一个序列,取其中的任何一个连续的序列,该序列的数从小到大排列,待更新,,,
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = ;
int num[MAXN];
int arr[MAXN];
int sum[MAXN*];
int cnt[MAXN];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i = ;i<=n;i++)
scanf("%d",&num[i]);
for(int i = ;i<=n;i++)
{
int temp = num[i];
memset(arr,,sizeof(arr));
memset(sum,,sizeof(sum));
int res = ;
for(int j = i-;j>=;j--)
{
arr[j] = arr[j+]+((num[j]>temp)?-:);
sum[arr[j]+n]++;
if(arr[j]==)
res++;
}
for(int j = i+;j<=n;j++)
{
arr[j] = arr[j-]+((num[j]>temp)?:-);
if(sum[arr[j]+n]>)
res=res+sum[arr[j]+n];
if(arr[j]==)
res++;
}
cnt[i] = res+;
}
printf("%d",cnt[]);
for(int i = ;i<=n;i++)
printf(" %d",cnt[i]);
printf("\n");
}
return ;
}
最新文章
- MVC代码中如何调用api接口
- myeclipse编译问题
- Aspose.Cells 首次使用,用到模版填充数据,合并单元格,换行
- Bringing up interface eth0: Error:Connection activation failed:Device not managed by NetworkManager
- 一个可能有用的封闭PGSQL操作的PYTHON函数
- Spring + iBatis 的多库横向切分简易解决思路
- ARM Cortex-M
- Ubuntu Server 14.04 LTS(64bit)已安装 weblogic Server 12c(12.1.3) Zip Distribution
- Array数组常用的5个方法
- 记录一次 “ORA-12516:TNS:监听程序找不到符合协议堆栈要求的可用处理程序” 的处理过程
- 单线程泵问题(com操作时间超过60s报错)
- shell 读取配置文件的方法
- python练习实例1--------给定数字组成三位数
- Scrum冲刺阶段1
- 【BZOJ1228】[SDOI2009]E&;D(博弈论)
- android侧滑删除,模仿qq跟进item显示删除按钮
- PRId64的正确用法
- centos安装eclise启动报错
- Pascal-S代码注释
- Buffer对象的总结