zoukankan      html  css  js  c++  java
  • cf #314 A. Lineland Mail

    A. Lineland Mail
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. 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 of ndistinct 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 test(s)
    input
    4
    -5 -2 2 7
    output
    3 12
    3 9
    4 7
    5 12
    input
    2
    -1 1
    output
    2 2
    2 2

     给一个有序序列,问对于没一个数,和它相差最少和最多的数的位置。

    /*************************************************************************
        > File Name: code/cf/#314/A.cpp
        > Author: 111qqz
        > Email: rkz2013@126.com 
        > Created Time: 2015年08月06日 星期四 00时01分51秒
     ************************************************************************/
    
    #include<iostream>
    #include<iomanip>
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<cstring>
    #include<string>
    #include<map>
    #include<set>
    #include<queue>
    #include<vector>
    #include<stack>
    #define y0 abc111qqz
    #define y1 hust111qqz
    #define yn hez111qqz
    #define j1 cute111qqz
    #define tm crazy111qqz
    #define lr dying111qqz
    using namespace std;
    #define REP(i, n) for (int i=0;i<int(n);++i)  
    typedef long long LL;
    typedef unsigned long long ULL;
    const int inf = 0x7fffffff;
    const int N=2E5+7;
    LL a[N];
    int main()
    {
        int n;
        cin>>n;
        a[0]=-inf;
        a[n+1]=inf;
    
        for ( int i  = 1 ; i <= n ; i ++ )
        {
        cin>>a[i];
        }
        int mx = -1;
        int mi = inf;
        cout<<a[2]-a[1]<<" "<<a[n]-a[1]<<endl;
        for ( int i = 2 ; i <= n-1 ; i++ )
        {
        cout<<min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i]))<<" "<<max(abs(a[i]-a[1]),abs(a[n]-a[i]))<<endl;
        }
        cout<<a[n]-a[n-1]<<" "<<a[n]-a[1]<<endl;
        return 0;
    }
  • 相关阅读:
    js+jq 淡入淡出轮播(点击+定时+鼠标进入移出事件)
    DBCA静默方式建库
    Oracle 11g常用管理命令(用户、表空间、权限)
    RedHat 7.3 Oracle 12.2.0.1 RAC 安装手册(转)
    rsyslog和logrotate服务
    Linux 之 rsyslog 系统日志转发
    Flatty Shadow图标自动产生器——在线生成各种扁平化 ICON
    助力前端开发——20个精心挑选新鲜好用的前端开发工具
    15款新鲜出炉的实用网页设计工具
    提供免费可商用的优秀背景视频素材——COVERR
  • 原文地址:https://www.cnblogs.com/111qqz/p/4706299.html
Copyright © 2011-2022 走看看