hdu 5701 中位数计数
2016-05-24 22:39
274 查看
题目链接
给一个数列, 每个数只出现一次。 问对于每个数, 有多少个区间是以它为中位数的。暴力统计, 对于每个数, 小于它的赋值-1, 大于它的赋值1. 然后暴力统计, 具体看代码。
和bzoj一个题一样啊....
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <complex> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef complex <double> cmx; typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; int l[16005], r[16005], a[8005], ans[8500], b[8005]; int main() { int n; while(cin>>n) { for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); } mem(ans); for(int i = 1; i <= n; i++) { memcpy(b, a, sizeof(a)); for(int j = 1; j <= n; j++) { if(i == j) { b[i] = 0; continue; } if(a[j]>a[i]) { b[j] = 1; } else { b[j] = -1; } } int sum = 0; mem(l); mem(r); l = r = 1; for(int j = i-1; j >= 1; j--) { sum += b[j]; l[sum+n]++; } sum = 0; for(int j = i+1; j <= n; j++) { sum += b[j]; r[sum+n]++; } for(int j = 0; j < 2*n; j++) { ans[i] += l[j]*r[2*n-j]; } } for(int i = 1; i < n; i++) { printf("%d ", ans[i]); } cout<<ans <<endl; } return 0; }
相关文章推荐
- 第二阶段每日总结02
- Android adapter设计模式一 静态设值
- leetcode.295. Find Median from Data Stream
- Echarts 使用总结
- leetcode---Roman to Integer
- c++作业6
- LinkedList集合源码解析
- TLV基础
- 飛飛(四十六)交通工具
- 数组中只出现一次的数字
- maven之window安装
- 【c++程序】friend与operator
- 4Sum
- 个人冲刺——第二天
- 面经中高频知识点归纳(四)
- Spark中组件Mllib的学习29之支持向量机SVM-方法2
- 【软考】这一个五月,你陪我一起走过
- 尝试解决JPA懒加载异常问题(wildfly)
- MATLAB与VC混编中的DLL加载问题
- Android UI设计之RecyclerView