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 }
  • 相关阅读:
    一个简单的加载动画,js实现
    banner无缝滚动动画,支持左右按钮和小点
    自动检测ie低版本,并显示升级浏览器的自定义页面,当用f12再把浏览器版本提高的时候,又会自动显示正常的页面。
    banner轮播无缝滚动 jq代码
    css 实现背景图片不跟着滚动条滚动而滚动
    截取字符串指定内容,并用*号代替
    日历获取当前月份的月数与当前月份第一天离第一个格子的位置。
    MUI 自定义从底部弹出的弹出框
    textarea 字体限制,超出部分不显示并及时显示还剩字体个数
    清除ul li里面的浮动并让ul自适应高度的一个好办法
  • 原文地址:https://www.cnblogs.com/zxhl/p/4706308.html
Copyright © 2011-2022 走看看