zoukankan      html  css  js  c++  java
  • 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]));
        }
    }
  • 相关阅读:
    Liferay 6.2 改造系列之十五:修改默认可用语言
    Liferay 6.2 改造系列之十七:当Portlet无权限时,不显示错误信息
    Liferay 6.2 改造系列之十四:修改组织的表单内容
    Liferay 6.2 改造系列之十三:修改用户编辑页面表单内容
    Liferay 6.2 改造系列之十一:默认关闭CDN动态资源
    matlab向量的排序(自写函数)
    matlab求一个矩阵中各元素出现的个数(归一化)
    matlab求矩阵的鞍点
    matlab求矩阵、向量的模
    matlab求最大公约数和最小公倍数
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4706301.html
Copyright © 2011-2022 走看看