zoukankan      html  css  js  c++  java
  • hlg1398邮局问题【找中位数】

    水题  直接上代码:

     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
    ", sum);
    26         }
    27     }
    28     return 0;
    29 }
    View Code
  • 相关阅读:
    Apache 基础
    Oracle
    DevOps
    Ansible
    Iptables 和Firewall 防火墙
    防火墙
    Linux
    Intellij IDEA 快捷键大全
    Java8,9 新特性
    Jmeter
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/4311921.html
Copyright © 2011-2022 走看看