zoukankan      html  css  js  c++  java
  • CodeForces 567A Gerald is into Art

    http://codeforces.com/problemset/problem/567/A

    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 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 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
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    #define N 100010
    #define INF 0x3f3f3f3f
    #define max(a, b)(a > b ? a : b)
    #define min(a, b)(a < b ? a : b)
    
    int c[N];
    int main()
    {
        int n, i, Min, Max;
        while(~scanf("%d", &n))
        {
            for(i = 1 ; i <= n ; i++)
                scanf("%d", &c[i]);
            printf("%d %d
    ", abs(c[1] - c[2]), abs(c[1] - c[n]));
            for(i = 2 ; i < n ; i++)
            {
                Min = min(abs(c[i] - c[i - 1]), abs(c[i] - c[i + 1]));
                Max = max(abs(c[1] - c[i]), abs(c[i] - c[n]));
                printf("%d %d
    ", Min, Max);
            }
            printf("%d %d
    ", abs(c[n] - c[n - 1]), abs(c[n] - c[1]));
        }
        return 0;
    }
  • 相关阅读:
    Docker为PHP安装gd扩展
    git修改远端仓库地址
    Oracle11g R2学习系列 之四Maven+Struts+Spring实验
    Oracle11g R2学习系列 之三教程选择
    Oracle11g R2学习系列 之二基本概念和环境介绍
    西雅图之行
    Oracle11g R2学习系列 之一安装篇
    Startcom SSL证书申请 IIS设置 配置 攻略
    StartCom 申请 SSL 证书及 Nginx HTTPS 支持配置全攻略
    没有了SA密码,无法Windows集成身份登录,DBA怎么办?
  • 原文地址:https://www.cnblogs.com/qq2424260747/p/4713130.html
Copyright © 2011-2022 走看看