hlg1398邮局问题【找中位数】
2015-04-25 18:09
141 查看
水题 直接上代码:
View Code
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 7 const int maxn = 1005; 8 int a[maxn]; 9 10 int main() { 11 int n, m; 12 int x, y; 13 while(EOF != scanf("%d",&n) ) { 14 for(int i = 1; i <= n; i++) { 15 scanf("%d",&a[i]); 16 } 17 scanf("%d",&m); 18 while(m--) { 19 scanf("%d %d",&x, &y); 20 int pos = ( x + y ) / 2; 21 long long sum = 0; 22 for(int i = x; i <= y; i++) { 23 sum += (long long) ( fabs(a[pos] - a[i]) ); 24 } 25 printf("%lld\n", sum); 26 } 27 } 28 return 0; 29 }
View Code
相关文章推荐
- hlg1398邮局问题【找中位数】
- hlg1398邮局问题【找中位数】
- 有序数组求中位数问题
- 杭电acm1157 中位数问题
- 【分步详解】两个有序数组中的中位数和Top K问题
- google笔试题两个n维数组logn求中位数问题【转载】
- Vijos 1691-输油管道问题【中位数】
- 利用对手论证法证明中位数问题的比较次数下界
- 求中位数的问题
- 【leetcode4】用分治算法计算中位数问题
- 基于计数排序求中位数问题的O(1)算法(Fraudulent Activity Notifications问题)
- 两个有序数组中的中位数和Top K问题(深度好文)
- 求俩个有序序列的中位数 ,和求众数问题
- (分治算法)两个有序数组中的中位数和Top K问题
- 3625 codevs 士兵站队问题 中位数的妙用
- 问题 D: 士兵排阵(中位数:贪心思想)
- nyoj7_街区最短路径问题(中位数)
- 中位数问题
- vijosp1691-中位数&贪心-输油管道问题
- CI20.9--中位数问题