zoukankan      html  css  js  c++  java
  • Codeforces Round #Pi (Div. 2) A. Lineland Mail 水

    A. Lineland Mail
    Time Limit: 2 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/567/problem/A

    Description

    All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Oxaxis. 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, and maxi 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 ofn 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 inascending 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.

    Sample Input

    4
    -5 -2 2 7

    Sample Output

    3 12
    3 9
    4 7
    5 12

    HINT

    题意

         在x轴上 ,给出n个点,输出每一个点的点间最小值和最大值

    题解

        最近就是相邻的点,最远就是端点

    代码

     

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <ctime>
     5 #include <iostream>
     6 #include <algorithm>
     7 #include <set>
     8 #include <vector>
     9 #include <queue>
    10 #include <typeinfo>
    11 #include <map>
    12 #include <stack>
    13 typedef __int64 ll;
    14 #define inf 1000000000000
    15 using namespace std;
    16 inline ll read()
    17 {
    18     ll x=0,f=1;
    19     char ch=getchar();
    20     while(ch<'0'||ch>'9')
    21     {
    22         if(ch=='-')f=-1;
    23         ch=getchar();
    24     }
    25     while(ch>='0'&&ch<='9')
    26     {
    27         x=x*10+ch-'0';
    28         ch=getchar();
    29     }
    30     return x*f;
    31 }
    32 
    33 //**************************************************************************************
    34  ll a[100005];
    35 int main()
    36 {
    37 
    38    ll n=read();
    39    ll minn=inf;
    40     ll maxx=-inf;
    41     a[0]=-inf;
    42     a[n+1]=inf;
    43     for(int i=1;i<=n;i++)
    44     {
    45         scanf("%I64d",&a[i]);
    46     }
    47     for(int i=1;i<=n;i++)
    48     {
    49         printf("%I64d ",min(a[i]-a[i-1],a[i+1]-a[i]));
    50         printf("%I64d
    ",max(a[i]-a[1],a[n]-a[i]));
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    【数论】X problem
    【数论】约瑟夫问题
    【组合数学】购票问题
    【组合数学】计数原理
    spring batch批处理框架学习
    eclipse自动添加javadoc注释
    eclipse手动安装alibaba代码规范插件
    现代支付系统的资金流向
    利用网易有道在谷歌浏览器进行网页滑词翻译
    spring配置遇到的问题
  • 原文地址:https://www.cnblogs.com/zxhl/p/4706308.html
Copyright © 2011-2022 走看看