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]));
        }
    }
  • 相关阅读:
    git 之gitignore 添加项之后生效的问题
    使用 padding-bottom 设置高度基于宽度的自适应
    ES5中新增的Array方法详细说明
    zepto.js 自定义打包集成其他模块构建流程
    移动端如何让页面强制横屏
    快来看看抓包工具有哪些?
    实践出真知,小程序wepy,uni-app框架开发使用!
    开发过程遇到的css样式问题记录
    带坑使用微信小程序框架WePY组件化开发项目,附带第三方插件使用坑
    微信 + weui 框架记录
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4706301.html
Copyright © 2011-2022 走看看