zoukankan      html  css  js  c++  java
  • Codeforce 567A

    All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.

    Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).

    Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.

    For each city calculate two values ​​mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, andmaxi is the the maximum cost of sending a letter from the i-th city to some other city

    Input

    The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.

    Output

    Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.

    Examples
    input
    4
    -5 -2 2 7
    output
    3 12
    3 9
    4 7
    5 12
    input
    2
    -1 1
    output
    2 2
    2 2

     思路:

    找出n个城市坐标最大和最小的点,对于第i个城市来说,花费最大的是到坐标最大的点或坐标最小的点,花费最小是到第i-1或i+1个点,记录所有的结果,并输出

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 using namespace std;
    13 #define lowbit(x) (x&(-x))
    14 #define max(x,y) (x>y?x:y)
    15 #define min(x,y) (x<y?x:y)
    16 #define MAX 100000000000000000
    17 #define MOD 1000000007
    18 #define pi acos(-1.0)
    19 #define ei exp(1)
    20 #define PI 3.141592653589793238462
    21 #define INF 0x3f3f3f3f3f
    22 #define mem(a) (memset(a,0,sizeof(a)))
    23 typedef long long LL;
    24 const int N=10005;
    25 const int mod=1e9+7;
    26 LL a[100010] , l , r ;
    27 int main() {
    28     int i , n ;
    29     scanf("%d", &n) ;
    30     for(i = 0 ; i < n ; i++)
    31         scanf("%I64d", &a[i]) ;
    32     l = a[0] ;
    33     r = a[n-1] ;
    34     printf("%I64d %I64d
    ", a[1]-a[0] , r - a[0] ) ;
    35     for(i = 1 ; i < n-1 ; i++) {
    36         printf("%I64d %I64d
    ", min(a[i]-a[i-1],a[i+1]-a[i]) , max(a[i]-l,r-a[i]) ) ;
    37     }
    38     printf("%I64d %I64d
    ", a[n-1]-a[n-2], a[n-1]-l ) ;
    39     return 0 ;
    40 }
     
  • 相关阅读:
    Data truncation: Out of range value for column 'quanity' at row 问题解决方案
    nginx 提示the "ssl" directive is deprecated, use the "listen ... ssl" directive instead
    集合源码分析[3]-ArrayList 源码分析
    集合源码分析[2]-AbstractList 源码分析
    IDEA升级版本后界面出现变小,字体变细的问题解决
    集合源码分析[1]-Collection 源码分析
    kubernetes学习第一篇-k8s安装以及HelloWorld
    shiro多Realm第一次调用不生效问题
    设计模式学习(二)-简单工厂模式
    根据具体的地址解析出对应的地区码
  • 原文地址:https://www.cnblogs.com/wydxry/p/7250543.html
Copyright © 2011-2022 走看看