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 }
  • 相关阅读:
    【转】Android系统中Fastboot和Recovery所扮演的角色。
    【转】Android ROM分析(1):刷机原理及方法
    【转】ANDROIDROM制作(一)——ROM结构介绍、精简和内置、一般刷机过程
    【转】使用fastboot命令刷机流程详解
    检测是否安装或者开启flash
    CentOS中/英文环境切换教程(CentOS6.8)
    id: cannot find name for user ID xxx处理办法
    linux重命名所有find查找到的文件/文件夹
    linux过滤旧文件中的空行和注释行剩余内容组成新文件
    CentOS和AIX查看系统序列号
  • 原文地址:https://www.cnblogs.com/zxhl/p/4706308.html
Copyright © 2011-2022 走看看