• Codeforces Round #Pi (Div. 2) A. Lineland Mail 水题


    A. Lineland Mail
    Time Limit: 20 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

    题意

    对于每个点,输出离这个点最近的点的距离,和离这个点最远的点的距离

    题解

    最近的点就是相邻的点,最远的点就是边界上的点

    代码

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)
    #define maxn 2000001
    #define mod 1000000007
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    ll a[maxn];
    int main()
    {
        int n=read();
        for(int i=1;i<=n;i++)
            a[i]=read();
        a[n+1]=infll;
        a[0]=-infll;
        sort(a,a+n);
        for(int i=1;i<=n;i++)
        {
            printf("%lld %lld
    ",min(a[i]-a[i-1],a[i+1]-a[i]),max(a[i]-a[1],a[n]-a[i]));
        }
    }
  • 相关阅读:
    [SDOI 2009] HH去散步
    [SDOI 2017] 新生舞会
    【期望 数学】7.6神经衰弱
    初涉2-SAT
    【tarjan 拓扑排序 dp】bzoj1093: [ZJOI2007]最大半连通子图
    【贪心】bzoj1572: [Usaco2009 Open]工作安排Job
    【贪心优化dp决策】bzoj1571: [Usaco2009 Open]滑雪课Ski
    概述「并查集补集转化」模型&&luoguP1330 封锁阳光大学
    初涉tarjan缩点
    初涉三元环
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4706301.html
Copyright © 2020-2023  润新知