2016"百度之星" - 初赛(Astar Round2B) 1006 中位数计数
思路:统计当前数左边比它小|大 i个人,相应右边就应该是比它大|小i个人
l数组表示左边i个人的方案
r表示右边i个人的方案
数组下标不可能是负数所以要加n
//#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-);
const LL MOD = 1e9+;
// const LL p = 1e9+7;
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// } int numm[],sum[],l[],r[];
int n,point,ans,b;
int a[]; int main() {
while(~scanf("%d",&n)) {
for(int i=; i<=n; i++) scanf("%d",&a[i]); for(int j=; j<=n; j++) {
b=a[j];
for(int i=;i<=n;i++) numm[i]=a[i];
// for(int i=0;i<=n;i++) l[i]=0;
// for(int i=0;i<=n;i++) r[i]=0;
// for(int i=0;i<=n;i++) sum[i]=0;
clc(l,);
clc(r,);
clc(sum,);
ans=;
for(int i=; i<=n; i++) {
if(numm[i]>b) numm[i]=;
else if(numm[i]==b) {
numm[i]=;
point=i;
} else numm[i]=-;
}
l[n]=;
r[n]=;
for(int i=point-; i>=; i--) {
sum[i]=sum[i+]+numm[i];
l[sum[i]+n]++;
}
for(int i=point+; i<=n; i++) {
sum[i]=sum[i-]+numm[i];
r[sum[i]+n]++;
}
for(int i=; i<=*n-; i++) ans+=l[i]*r[*n-i]; if(j==)
printf("%d",ans);
else
printf(" %d",ans);
}
printf("\n");
}
return ;
}
2016"百度之星" - 初赛(Astar Round2B) 1006 中位数计数的更多相关文章
- 2016百度之星-初赛(Astar Round2A)AII X
Problem Description F(x,m) 代表一个全是由数字x组成的m位数字.请计算,以下式子是否成立: F(x,m) mod k ≡ c Input 第一行一个整数T,表示T组数据. 每 ...
- 2016"百度之星" - 初赛(Astar Round2A)HDU 5695 拓扑排序+优先队列
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- 2016百度之星 初赛2A ABEF
只做了1001 1002 1005 1006.剩下2题可能以后补? http://acm.hdu.edu.cn/search.php?field=problem&key=2016%22%B0% ...
- HDU 5690:2016"百度之星" - 初赛 All X
原文链接:https://www.dreamwings.cn/hdu5690/2657.html All X Time Limit: 2000/1000 MS (Java/Others) Mem ...
- 2016百度之星 初赛2B ACEF
做了1001 1003 1005 1006 看题:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=702 交题:http://acm ...
- 2016"百度之星" - 初赛(Astar Round2B)
Problem Description 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数. 现在有n个数,每个数都是独一无二的,求出每个数在 ...
- 2016"百度之星" - 初赛(Astar Round2B)1003 瞬间移动 组合数学+逆元
瞬间移动 Accepts: 1018 Submissions: 3620 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/ ...
- 2016"百度之星" - 初赛(Astar Round2A) 1006 Gym Class 拓扑排序
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- hdu5696区间的价值 -- 2016"百度之星" - 初赛(Astar Round2B)
Problem Description 我们定义“区间的价值”为一段区间的最大值*最小值. 一个区间左端点在L,右端点在R,那么该区间的长度为(R−L+1). 现在聪明的杰西想要知道,对于长度为k的区 ...
随机推荐
- C#学习笔记(一)
1.cmd运行devenv启动VS. 2.解决方案:公司 项目:部门 类:员工 3.右边的解决方案管理器:会自动隐藏,想让他固定的话,就点击关闭按钮中间的“自动隐藏”:可以拖动到上下左右,当出现阴影的 ...
- spoj 24
大数 #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> ...
- cocos2d-x 常规库的图文件配置
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS) LOCAL_MODULE := cocos_lua_static LOCAL_MODULE_FILE ...
- [itint5]两数积全为1
http://www.itint5.com/oj/#18 这一题,首先如果直接去算的话,很容易就超出int或者long的表示范围了.那么要利用%的性质,(num * 10 + 1) % a = 10 ...
- Qt: 把内容写进字符串中与C++很相似(使用QTextStream包装QString)
#include <iostream>#include <QChar>#include <QFile>#include <QTextStream>#in ...
- FastScroll(3)分组的listview 打开fastscroll的分组提示功能
1,让ListView显示分组(用两个layout) 2,让ListView实现sectionIndexer接口 3,代码如下: import java.util.ArrayList; import ...
- Visual C#每一次新版本的变化
What's New in Visual C# .NET 2003[Visual Studio .NET 2003] What's New in Visual C# 2005 What's New i ...
- Dapper连接Oracle
Dapper连接Oracle去年写过了篇博客,名字叫:让dapper支持Oracle 网址:http://www.cnblogs.com/ushou/archive/2012/09/28/270690 ...
- I.MX6 Android frameworks services 文件架构
/******************************************************************************* * I.MX6 Android fra ...
- OK335xS LAN8710 phy driver hacking
/******************************************************************** * OK335xS LAN8710 phy driver h ...